Commit 731cc93b authored by yogevbd's avatar yogevbd

Verify FCM notification intent

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