diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/interfaces/IRNPushNotificationBundleEditor.java b/android/src/main/java/com/dieam/reactnativepushnotification/interfaces/IRNPushNotificationBundleEditor.java new file mode 100644 index 000000000..dfc1ae7d5 --- /dev/null +++ b/android/src/main/java/com/dieam/reactnativepushnotification/interfaces/IRNPushNotificationBundleEditor.java @@ -0,0 +1,9 @@ +package com.dieam.reactnativepushnotification.interfaces; + +import android.os.Bundle; + +import com.google.firebase.messaging.RemoteMessage; + +public interface IRNPushNotificationBundleEditor { + public void editBundle(Bundle bundle, RemoteMessage message); +} diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java index ca78c0363..e052ef688 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java @@ -1,5 +1,6 @@ package com.dieam.reactnativepushnotification.modules; +import com.dieam.reactnativepushnotification.types.RNPushNotificationUserConfig; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; @@ -26,12 +27,23 @@ public RNPushNotificationListenerService() { this.mMessageReceivedHandler = new RNReceivedMessageHandler(this); } + public RNPushNotificationListenerService(RNPushNotificationUserConfig userConfig) { + super(); + this.mMessageReceivedHandler = new RNReceivedMessageHandler(this, userConfig); + } + public RNPushNotificationListenerService(FirebaseMessagingService delegate) { super(); this.mFirebaseServiceDelegate = delegate; this.mMessageReceivedHandler = new RNReceivedMessageHandler(delegate); } + public RNPushNotificationListenerService(FirebaseMessagingService delegate, RNPushNotificationUserConfig userConfig) { + super(); + this.mFirebaseServiceDelegate = delegate; + this.mMessageReceivedHandler = new RNReceivedMessageHandler(delegate, userConfig); + } + @Override public void onNewToken(String token) { final String deviceToken = token; diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java index 721ca40cc..ca4e50076 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNReceivedMessageHandler.java @@ -1,5 +1,6 @@ package com.dieam.reactnativepushnotification.modules; +import com.dieam.reactnativepushnotification.types.RNPushNotificationUserConfig; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; @@ -32,11 +33,17 @@ public class RNReceivedMessageHandler { private FirebaseMessagingService mFirebaseMessagingService; + private RNPushNotificationUserConfig userConfig; public RNReceivedMessageHandler(@NonNull FirebaseMessagingService service) { this.mFirebaseMessagingService = service; } + public RNReceivedMessageHandler(@NonNull FirebaseMessagingService service, RNPushNotificationUserConfig userConfig) { + this.mFirebaseMessagingService = service; + this.userConfig = userConfig; + } + public void handleReceivedMessage(RemoteMessage message) { String from = message.getFrom(); RemoteMessage.Notification remoteNotification = message.getNotification(); @@ -128,6 +135,11 @@ public void handleReceivedMessage(RemoteMessage message) { Log.v(LOG_TAG, "onMessageReceived: " + bundle); + if (this.userConfig != null && this.userConfig.getPushNotificationBundleEditor() != null) { + this.userConfig.getPushNotificationBundleEditor().editBundle(bundle, message); + Log.v(LOG_TAG, "onBundleEditedByUser: " + bundle); + } + // We need to run this on the main thread, as the React code assumes that is true. // Namely, DevServerHelper constructs a Handler() without a Looper, which triggers: // "Can't create handler inside thread that has not called Looper.prepare()" diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/types/RNPushNotificationUserConfig.java b/android/src/main/java/com/dieam/reactnativepushnotification/types/RNPushNotificationUserConfig.java new file mode 100644 index 000000000..b4ff02865 --- /dev/null +++ b/android/src/main/java/com/dieam/reactnativepushnotification/types/RNPushNotificationUserConfig.java @@ -0,0 +1,15 @@ +package com.dieam.reactnativepushnotification.types; + +import com.dieam.reactnativepushnotification.interfaces.IRNPushNotificationBundleEditor; + +public class RNPushNotificationUserConfig { + private IRNPushNotificationBundleEditor pushNotificationBundleEditor; + + public void setPushNotificationBundleEditor(IRNPushNotificationBundleEditor pushNotificationBundleEditor) { + this.pushNotificationBundleEditor = pushNotificationBundleEditor; + } + + public IRNPushNotificationBundleEditor getPushNotificationBundleEditor() { + return this.pushNotificationBundleEditor; + } +}