diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotifications.java @@ -176,6 +176,17 @@ final Map constants = new HashMap<>(); constants.put( "NOTIFICATIONS_IMPORTANCE_HIGH", NotificationManager.IMPORTANCE_HIGH); + constants.put( + "COMM_ANDROID_NOTIFICATIONS_TOKEN", + CommAndroidNotificationsEventEmitter.COMM_ANDROID_NOTIFICATIONS_TOKEN); + constants.put( + "COMM_ANDROID_NOTIFICATIONS_MESSAGE", + CommAndroidNotificationsEventEmitter + .COMM_ANDROID_NOTIFICATIONS_MESSAGE); + constants.put( + "COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED", + CommAndroidNotificationsEventEmitter + .COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED); return constants; } diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsEventEmitter.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsEventEmitter.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsEventEmitter.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationsEventEmitter.java @@ -22,6 +22,13 @@ private static final String TAG = "CommAndroidNotifications"; private volatile int listenersCount = 0; + public static final String COMM_ANDROID_NOTIFICATIONS_TOKEN = + "commAndroidNotificationsToken"; + public static final String COMM_ANDROID_NOTIFICATIONS_MESSAGE = + "commAndroidNotificationsMessage"; + public static final String COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED = + "commAndroidNotificationsNotificationOpened"; + CommAndroidNotificationsEventEmitter(ReactApplicationContext reactContext) { super(reactContext); reactContext.addActivityEventListener( @@ -76,7 +83,8 @@ initialNotification); if (jsReadableNotification != null) { sendEventToJS( - "commAndroidNotificationsNotificationOpened", jsReadableNotification); + COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED, + jsReadableNotification); } } @@ -85,7 +93,7 @@ @Override public void onReceive(Context context, Intent intent) { String token = intent.getStringExtra("token"); - sendEventToJS("commAndroidNotificationsToken", token); + sendEventToJS(COMM_ANDROID_NOTIFICATIONS_TOKEN, token); } } @@ -97,7 +105,7 @@ WritableMap jsMessage = CommAndroidNotificationParser.parseRemoteMessageToJSMessage(message); if (jsMessage != null) { - sendEventToJS("commAndroidNotificationsMessage", jsMessage); + sendEventToJS(COMM_ANDROID_NOTIFICATIONS_MESSAGE, jsMessage); } } } diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -4,6 +4,13 @@ import { mergePrefixIntoBody } from 'lib/shared/notif-utils.js'; +type CommAndroidNotificationsConstants = { + +NOTIFICATIONS_IMPORTANCE_HIGH: number, + +COMM_ANDROID_NOTIFICATIONS_TOKEN: 'commAndroidNotificationsToken', + +COMM_ANDROID_NOTIFICATIONS_MESSAGE: 'commAndroidNotificationsMessage', + +COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED: 'commAndroidNotificationsNotificationOpened', +}; + type CommAndroidNotificationsModuleType = { +removeAllActiveNotificationsForThread: (threadID: string) => void, +getInitialNotification: () => Promise, @@ -13,14 +20,14 @@ importance: number, description: ?string, ) => void, - +getConstants: () => { +NOTIFICATIONS_IMPORTANCE_HIGH: number, ... }, + +getConstants: () => CommAndroidNotificationsConstants, +setBadge: (count: number) => void, +removeAllDeliveredNotifications: () => void, +hasPermission: () => Promise, +getToken: () => Promise, +requestNotificationsPermission: () => Promise, +canRequestNotificationsPermissionFromUser: () => Promise, - +NOTIFICATIONS_IMPORTANCE_HIGH: string, + ...CommAndroidNotificationsConstants, }; export type AndroidMessage = { +body: string, diff --git a/native/push/push-handler.react.js b/native/push/push-handler.react.js --- a/native/push/push-handler.react.js +++ b/native/push/push-handler.react.js @@ -167,15 +167,18 @@ getCommAndroidNotificationsEventEmitter(); this.androidNotificationsEventSubscriptions.push( commAndroidNotificationsEventEmitter.addListener( - 'commAndroidNotificationsToken', + CommAndroidNotifications.getConstants() + .COMM_ANDROID_NOTIFICATIONS_TOKEN, this.handleAndroidDeviceToken, ), commAndroidNotificationsEventEmitter.addListener( - 'commAndroidNotificationsMessage', + CommAndroidNotifications.getConstants() + .COMM_ANDROID_NOTIFICATIONS_MESSAGE, this.androidMessageReceived, ), commAndroidNotificationsEventEmitter.addListener( - 'commAndroidNotificationsNotificationOpened', + CommAndroidNotifications.getConstants() + .COMM_ANDROID_NOTIFICATIONS_NOTIFICATION_OPENED, this.androidNotificationOpened, ), );