Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3486843
D6274.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D6274.diff
View Options
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
@@ -137,7 +137,9 @@
}
if (this.isAppInForeground()) {
- super.onMessageReceived(message);
+ 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
@@ -1,8 +1,6 @@
// @flow
-import invariant from 'invariant';
import { NativeModules, NativeEventEmitter } from 'react-native';
-import type { RemoteMessage } from 'react-native-firebase';
import { mergePrefixIntoBody } from 'lib/shared/notif-utils';
@@ -10,6 +8,13 @@
+removeAllActiveNotificationsForThread: (threadID: string) => void,
...
};
+export type AndroidForegroundMessage = {
+ +body: string,
+ +title: string,
+ +threadID: string,
+ +prefix?: string,
+ +messageInfos: ?string,
+};
const { CommAndroidNotificationsEventEmitter } = NativeModules;
const CommAndroidNotifications: CommAndroidNotificationsModuleType =
@@ -17,23 +22,15 @@
const androidNotificationChannelID = 'default';
function handleAndroidMessage(
- message: RemoteMessage,
+ message: AndroidForegroundMessage,
updatesCurrentAsOf: number,
handleIfActive?: (
threadID: string,
texts: { body: string, title: ?string },
) => boolean,
) {
- const { data } = message;
-
- const { rescind, rescindID } = data;
- if (rescind) {
- invariant(rescindID, 'rescind message without notifID');
- return;
- }
-
- const { title, prefix, threadID } = data;
- let { body } = data;
+ const { title, prefix, threadID } = message;
+ let { body } = message;
({ body } = mergePrefixIntoBody({ body, title, prefix }));
if (handleIfActive) {
@@ -44,8 +41,10 @@
}
}
}
+
function getCommAndroidNotificationsEventEmitter(): NativeEventEmitter<{
commAndroidNotificationsToken: [string],
+ commAndroidNotificationsForegroundMessage: [AndroidForegroundMessage],
}> {
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
@@ -3,7 +3,7 @@
import * as Haptics from 'expo-haptics';
import * as React from 'react';
import { Platform, Alert, LogBox } from 'react-native';
-import type { RemoteMessage, NotificationOpen } from 'react-native-firebase';
+import type { NotificationOpen } from 'react-native-firebase';
import { Notification as InAppNotification } from 'react-native-in-app-message';
import { useDispatch } from 'react-redux';
@@ -50,6 +50,7 @@
androidNotificationChannelID,
handleAndroidMessage,
getCommAndroidNotificationsEventEmitter,
+ type AndroidForegroundMessage,
CommAndroidNotifications,
} from './android';
import {
@@ -115,7 +116,6 @@
currentState: ?string = getCurrentLifecycleState();
appStarted = 0;
androidNotificationsEventSubscriptions: Array<EventSubscription> = [];
- androidMessageListener: ?() => void = null;
androidNotifOpenListener: ?() => void = null;
initialAndroidNotifHandled = false;
openThreadOnceReceived: Set<string> = new Set();
@@ -163,10 +163,12 @@
'commAndroidNotificationsToken',
this.handleAndroidDeviceToken,
),
+ commAndroidNotificationsEventEmitter.addListener(
+ 'commAndroidNotificationsForegroundMessage',
+ this.androidMessageReceived,
+ ),
);
- this.androidMessageListener = firebase
- .messaging()
- .onMessage(this.androidMessageReceived);
+
this.androidNotifOpenListener = firebase
.notifications()
.onNotificationOpened(this.androidNotificationOpened);
@@ -192,10 +194,6 @@
androidNotificationsEventSubscription.remove();
}
this.androidNotificationsEventSubscriptions = [];
- if (this.androidMessageListener) {
- this.androidMessageListener();
- this.androidMessageListener = null;
- }
if (this.androidNotifOpenListener) {
this.androidNotifOpenListener();
this.androidNotifOpenListener = null;
@@ -548,11 +546,10 @@
this.onPressNotificationForThread(threadID, true);
};
- androidMessageReceived = async (message: RemoteMessage) => {
+ androidMessageReceived = async (message: AndroidForegroundMessage) => {
this.onPushNotifBootsApp();
- const { data } = message;
- const { messageInfos } = data;
+ const { messageInfos } = message;
this.saveMessageInfos(messageInfos);
handleAndroidMessage(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 6:11 AM (21 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2675632
Default Alt Text
D6274.diff (4 KB)
Attached To
Mode
D6274: Send broadcast from CommNotificationsHandler when foreground notification is received. Forward parsed notification to JavaScript
Attached
Detach File
Event Timeline
Log In to Comment