Commit 731cc93b authored by yogevbd's avatar yogevbd

Verify FCM notification intent

parent 4cd72c48
......@@ -65,9 +65,11 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
Bundle notificationData = intent.getExtras();
if (notificationData != null) {
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData);
if (notification != null) {
notification.onOpened();
}
}
}
@ReactMethod
public void refreshToken() {
......
......@@ -63,7 +63,9 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
final IPushNotificationsDrawer notificationsDrawer = PushNotificationsDrawer.get(mApplication.getApplicationContext());
notificationsDrawer.onNewActivity(activity);
Bundle notificationData = activity.getIntent().getExtras();
Intent intent = activity.getIntent();
if (intent != null) {
Bundle notificationData = intent.getExtras();
if (notificationData != null) {
final IPushNotification pushNotification = PushNotification.get(mApplication.getApplicationContext(), notificationData);
if (pushNotification != null) {
......@@ -71,6 +73,7 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
}
}
}
}
@Override
public void onActivityStarted(Activity activity) {
......
......@@ -43,6 +43,10 @@ public class PushNotification implements IPushNotification {
};
public static IPushNotification get(Context context, Bundle bundle) {
if (verifyNotificationBundle(bundle) == false) {
return null;
}
Context appContext = context.getApplicationContext();
if (appContext instanceof INotificationsApplication) {
return ((INotificationsApplication) appContext).getPushNotification(context, bundle, AppLifecycleFacadeHolder.get(), new AppLaunchHelper());
......@@ -58,6 +62,14 @@ public class PushNotification implements IPushNotification {
mNotificationProps = createProps(bundle);
}
private static boolean verifyNotificationBundle(Bundle bundle) {
if (bundle.getString("google.message_id") != null) {
return true;
}
return false;
}
@Override
public void onReceived() throws InvalidNotificationException {
postNotification(null);
......
......@@ -21,8 +21,7 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage message){
Map data = message.getData();
Bundle bundle = convertMapToBundle(data);
Bundle bundle = message.toIntent().getExtras();
Log.d(LOGTAG, "New message from GCM: " + bundle);
try {
......@@ -33,14 +32,4 @@ public class FcmInstanceIdListenerService extends FirebaseMessagingService {
Log.v(LOGTAG, "GCM message handling aborted", e);
}
}
private Bundle convertMapToBundle(Map<String, String> map) {
Bundle bundle = new Bundle();
for (Map.Entry<String, String> entry : map.entrySet()) {
bundle.putString(entry.getKey(), entry.getValue());
}
return bundle;
}
}
{
"name": "react-native-notifications",
"version": "1.2.5",
"version": "1.2.51",
"description": "Advanced Push Notifications (Silent, interactive notifications) for iOS & Android",
"author": "Lidan Hifi <lidan.hifi@gmail.com>",
"license": "MIT",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment