Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

feat(android): Add user config. Add push notification bundle edit possibility before processing #2070

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}