From da835d026e0654098e4279e7db81e4d312834fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lindstro=CC=88m?= Date: Tue, 1 Dec 2020 14:18:59 +0100 Subject: [PATCH] Try to get remote message from messaging store on new intent --- .../ReactNativeFirebaseMessagingModule.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java b/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java index efe88d29cc9..88b66da7227 100644 --- a/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java +++ b/packages/messaging/android/src/main/java/io/invertase/firebase/messaging/ReactNativeFirebaseMessagingModule.java @@ -49,6 +49,13 @@ public class ReactNativeFirebaseMessagingModule extends ReactNativeFirebaseModul reactContext.addActivityEventListener(this); } + private RemoteMessage popRemoteMessageFromMessagingStore(String messageId) { + ReactNativeFirebaseMessagingStore messagingStore = ReactNativeFirebaseMessagingStoreHelper.getInstance().getMessagingStore(); + RemoteMessage remoteMessage = messagingStore.getFirebaseMessage(messageId); + messagingStore.clearFirebaseMessage(messageId); + return remoteMessage; + } + @ReactMethod public void getInitialNotification(Promise promise) { if (initialNotification != null) { @@ -70,9 +77,7 @@ public void getInitialNotification(Promise promise) { if (messageId != null && initialNotificationMap.get(messageId) == null) { RemoteMessage remoteMessage = ReactNativeFirebaseMessagingReceiver.notifications.get(messageId); if (remoteMessage == null) { - ReactNativeFirebaseMessagingStore messagingStore = ReactNativeFirebaseMessagingStoreHelper.getInstance().getMessagingStore(); - remoteMessage = messagingStore.getFirebaseMessage(messageId); - messagingStore.clearFirebaseMessage(messageId); + remoteMessage = popRemoteMessageFromMessagingStore(messageId); } if (remoteMessage != null) { promise.resolve(ReactNativeFirebaseMessagingSerializer.remoteMessageToWritableMap(remoteMessage)); @@ -212,6 +217,9 @@ public void onNewIntent(Intent intent) { if (messageId != null) { RemoteMessage remoteMessage = ReactNativeFirebaseMessagingReceiver.notifications.get(messageId); + if (remoteMessage == null) { + remoteMessage = popRemoteMessageFromMessagingStore(messageId); + } if (remoteMessage != null) { initialNotification = remoteMessage;