diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationParser.java b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationParser.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationParser.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommAndroidNotificationParser.java @@ -17,18 +17,18 @@ CommNotificationsHandler.PREFIX_KEY); public static WritableMap - parseRemoteMessageToJSForegroundMessage(RemoteMessage message) { + parseRemoteMessageToJSMessage(RemoteMessage message) { if (message.getData() == null) { return null; } - WritableMap jsForegroundMessage = Arguments.createMap(); + WritableMap jsMessage = Arguments.createMap(); for (String key : OBLIGATORY_KEYS) { String value = message.getData().get(key); if (value == null) { return null; } - jsForegroundMessage.putString(key, value); + jsMessage.putString(key, value); } for (String key : OPTIONAL_KEYS) { @@ -36,9 +36,9 @@ if (value == null) { continue; } - jsForegroundMessage.putString(key, value); + jsMessage.putString(key, value); } - return jsForegroundMessage; + return jsMessage; } } 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 @@ -78,7 +78,7 @@ return; } WritableMap jsReadableNotification = - CommAndroidNotificationParser.parseRemoteMessageToJSForegroundMessage( + CommAndroidNotificationParser.parseRemoteMessageToJSMessage( initialNotification); promise.resolve(jsReadableNotification); } 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 @@ -32,8 +32,8 @@ new CommAndroidNotificationsTokenReceiver(), new IntentFilter(CommNotificationsHandler.TOKEN_EVENT)); localBroadcastManager.registerReceiver( - new CommAndroidNotificationsForegroundMessageReceiver(), - new IntentFilter(CommNotificationsHandler.FOREGROUND_MESSAGE_EVENT)); + new CommAndroidNotificationsMessageReceiver(), + new IntentFilter(CommNotificationsHandler.MESSAGE_EVENT)); } @Override @@ -72,7 +72,7 @@ return; } WritableMap jsReadableNotification = - CommAndroidNotificationParser.parseRemoteMessageToJSForegroundMessage( + CommAndroidNotificationParser.parseRemoteMessageToJSMessage( initialNotification); if (jsReadableNotification != null) { sendEventToJS( @@ -89,17 +89,15 @@ } } - private class CommAndroidNotificationsForegroundMessageReceiver + private class CommAndroidNotificationsMessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { RemoteMessage message = intent.getParcelableExtra("message"); - WritableMap jsForegroundMessage = - CommAndroidNotificationParser.parseRemoteMessageToJSForegroundMessage( - message); - if (jsForegroundMessage != null) { - sendEventToJS( - "commAndroidNotificationsForegroundMessage", jsForegroundMessage); + WritableMap jsMessage = + CommAndroidNotificationParser.parseRemoteMessageToJSMessage(message); + if (jsMessage != null) { + sendEventToJS("commAndroidNotificationsMessage", jsMessage); } } } diff --git a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java --- a/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java +++ b/native/android/app/src/main/java/app/comm/android/notifications/CommNotificationsHandler.java @@ -49,8 +49,7 @@ public static final String THREAD_ID_KEY = "threadID"; public static final String TOKEN_EVENT = "TOKEN_EVENT"; - public static final String FOREGROUND_MESSAGE_EVENT = - "FOREGROUND_MESSAGE_EVENT"; + public static final String MESSAGE_EVENT = "MESSAGE_EVENT"; @Override public void onCreate() { @@ -113,10 +112,11 @@ Log.w("COMM", "Database not existing yet. Skipping notification"); } + Intent intent = new Intent(MESSAGE_EVENT); + intent.putExtra("message", message); + localBroadcastManager.sendBroadcast(intent); + if (this.isAppInForeground()) { - Intent intent = new Intent(FOREGROUND_MESSAGE_EVENT); - intent.putExtra("message", message); - localBroadcastManager.sendBroadcast(intent); return; } this.displayNotification(message); diff --git a/native/push/android.js b/native/push/android.js --- a/native/push/android.js +++ b/native/push/android.js @@ -6,7 +6,7 @@ type CommAndroidNotificationsModuleType = { +removeAllActiveNotificationsForThread: (threadID: string) => void, - +getInitialNotification: () => Promise, + +getInitialNotification: () => Promise, +createChannel: ( channelID: string, name: string, @@ -22,7 +22,7 @@ +canRequestNotificationsPermissionFromUser: () => Promise, +NOTIFICATIONS_IMPORTANCE_HIGH: string, }; -export type AndroidForegroundMessage = { +export type AndroidMessage = { +body: string, +title: string, +threadID: string, @@ -36,7 +36,7 @@ const androidNotificationChannelID = 'default'; function handleAndroidMessage( - message: AndroidForegroundMessage, + message: AndroidMessage, updatesCurrentAsOf: number, handleIfActive?: ( threadID: string, @@ -58,8 +58,8 @@ function getCommAndroidNotificationsEventEmitter(): NativeEventEmitter<{ commAndroidNotificationsToken: [string], - commAndroidNotificationsForegroundMessage: [AndroidForegroundMessage], - commAndroidNotificationsNotificationOpened: [AndroidForegroundMessage], + commAndroidNotificationsMessage: [AndroidMessage], + commAndroidNotificationsNotificationOpened: [AndroidMessage], }> { return new NativeEventEmitter(CommAndroidNotificationsEventEmitter); } 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 @@ -37,7 +37,7 @@ androidNotificationChannelID, handleAndroidMessage, getCommAndroidNotificationsEventEmitter, - type AndroidForegroundMessage, + type AndroidMessage, CommAndroidNotifications, } from './android.js'; import { @@ -163,7 +163,7 @@ this.handleAndroidDeviceToken, ), commAndroidNotificationsEventEmitter.addListener( - 'commAndroidNotificationsForegroundMessage', + 'commAndroidNotificationsMessage', this.androidMessageReceived, ), commAndroidNotificationsEventEmitter.addListener( @@ -561,15 +561,13 @@ }); } - androidNotificationOpened = async ( - notificationOpen: AndroidForegroundMessage, - ) => { + androidNotificationOpened = async (notificationOpen: AndroidMessage) => { this.onPushNotifBootsApp(); const { threadID } = notificationOpen; this.onPressNotificationForThread(threadID, true); }; - androidMessageReceived = async (message: AndroidForegroundMessage) => { + androidMessageReceived = async (message: AndroidMessage) => { this.onPushNotifBootsApp(); const { messageInfos } = message;