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

Add possibility to use custom handlers on 'handleReceivedMessage' #2345

Open
wants to merge 2 commits 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,7 @@
package com.dieam.reactnativepushnotification.modules;

import android.os.Bundle;

public interface RNReceivedMessageCustomHandler {
void onMessageReceived(Bundle bundle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;
import java.security.SecureRandom;
Expand All @@ -33,6 +34,8 @@
public class RNReceivedMessageHandler {
private FirebaseMessagingService mFirebaseMessagingService;

public static List<RNReceivedMessageCustomHandler> CustomHandlers = new ArrayList();

public RNReceivedMessageHandler(@NonNull FirebaseMessagingService service) {
this.mFirebaseMessagingService = service;
}
Expand Down Expand Up @@ -128,6 +131,10 @@ public void handleReceivedMessage(RemoteMessage message) {

Log.v(LOG_TAG, "onMessageReceived: " + bundle);

for (RNReceivedMessageCustomHandler handler : CustomHandlers) {
handler.onMessageReceived(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