Commit 5056657a authored by yogevbd's avatar yogevbd

Handle intent by extra key and not by google.message_id string

parent f8296ddd
...@@ -189,3 +189,4 @@ package-lock.json ...@@ -189,3 +189,4 @@ package-lock.json
.history .history
android/.idea android/.idea
android/build android/build
android/.gradle
\ No newline at end of file
#Tue Mar 05 16:05:24 EET 2019 #Mon Aug 12 14:22:42 IDT 2019
gradle.version=4.4 gradle.version=4.4
...@@ -18,6 +18,7 @@ import com.facebook.react.bridge.ReadableMap; ...@@ -18,6 +18,7 @@ import com.facebook.react.bridge.ReadableMap;
import com.wix.reactnativenotifications.core.AppLifecycleFacade; import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder; import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
import com.wix.reactnativenotifications.core.InitialNotificationHolder; import com.wix.reactnativenotifications.core.InitialNotificationHolder;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade; import com.wix.reactnativenotifications.core.ReactAppLifecycleFacade;
import com.wix.reactnativenotifications.core.notification.IPushNotification; import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification;
...@@ -62,8 +63,8 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements ...@@ -62,8 +63,8 @@ public class RNNotificationsModule extends ReactContextBaseJavaModule implements
@Override @Override
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = intent.getExtras(); Bundle notificationData = intent.getExtras();
if (notificationData != null) {
final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData); final IPushNotification notification = PushNotification.get(getReactApplicationContext().getApplicationContext(), notificationData);
if (notification != null) { if (notification != null) {
notification.onOpened(); notification.onOpened();
......
...@@ -14,6 +14,7 @@ import com.facebook.react.uimanager.ViewManager; ...@@ -14,6 +14,7 @@ import com.facebook.react.uimanager.ViewManager;
import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseApp;
import com.wix.reactnativenotifications.core.AppLifecycleFacade; import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder; import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.notification.IPushNotification; import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification; import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer; import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
...@@ -64,16 +65,14 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade. ...@@ -64,16 +65,14 @@ public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.
notificationsDrawer.onNewActivity(activity); notificationsDrawer.onNewActivity(activity);
Intent intent = activity.getIntent(); Intent intent = activity.getIntent();
if (intent != null) { if (NotificationIntentAdapter.canHandleIntent(intent)) {
Bundle notificationData = intent.getExtras(); Bundle notificationData = intent.getExtras();
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) {
pushNotification.onOpened(); pushNotification.onOpened();
} }
} }
} }
}
@Override @Override
public void onActivityStarted(Activity activity) { public void onActivityStarted(Activity activity) {
......
...@@ -18,4 +18,15 @@ public class NotificationIntentAdapter { ...@@ -18,4 +18,15 @@ public class NotificationIntentAdapter {
public static Bundle extractPendingNotificationDataFromIntent(Intent intent) { public static Bundle extractPendingNotificationDataFromIntent(Intent intent) {
return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME); return intent.getBundleExtra(PUSH_NOTIFICATION_EXTRA_NAME);
} }
public static boolean canHandleIntent(Intent intent) {
if (intent != null) {
Bundle notificationData = intent.getExtras();
if (notificationData != null && intent.hasExtra(PUSH_NOTIFICATION_EXTRA_NAME)) {
return true;
}
}
return false;
}
} }
...@@ -8,6 +8,8 @@ import android.content.Context; ...@@ -8,6 +8,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Debug;
import android.util.Log;
import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContext;
import com.wix.reactnativenotifications.core.AppLaunchHelper; import com.wix.reactnativenotifications.core.AppLaunchHelper;
...@@ -43,10 +45,6 @@ public class PushNotification implements IPushNotification { ...@@ -43,10 +45,6 @@ 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());
...@@ -62,14 +60,6 @@ public class PushNotification implements IPushNotification { ...@@ -62,14 +60,6 @@ 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);
......
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