Skip to content

Fix initial notification data lost issue and empty foreground notification issue #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2020
Merged
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
Expand Up @@ -4,28 +4,25 @@
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.google.firebase.FirebaseApp;
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
import com.wix.reactnativenotifications.core.InitialNotificationHolder;
import com.wix.reactnativenotifications.core.NotificationIntentAdapter;
import com.wix.reactnativenotifications.core.notification.IPushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotification;
import com.wix.reactnativenotifications.core.notification.PushNotificationProps;
import com.wix.reactnativenotifications.core.notificationdrawer.IPushNotificationsDrawer;
import com.wix.reactnativenotifications.core.notificationdrawer.PushNotificationsDrawer;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static com.wix.reactnativenotifications.Defs.LOGTAG;

public class RNNotificationsPackage implements ReactPackage, AppLifecycleFacade.AppVisibilityListener, Application.ActivityLifecycleCallbacks {

Expand Down Expand Up @@ -76,6 +73,13 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

@Override
public void onActivityStarted(Activity activity) {
Bundle bundle = activity.getIntent().getExtras();
if (bundle != null) {
PushNotificationProps props = new PushNotificationProps(bundle);
if (props.isFirebaseBackgroundPayload()) {
InitialNotificationHolder.getInstance().set(props);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ public PushNotificationProps(Bundle bundle) {
}

public String getTitle() {
return mBundle.getString("title");
return getBundleStringFirstNotNull("gcm.notification.title", "title");
}

public String getBody() {
return mBundle.getString("body");
return getBundleStringFirstNotNull("gcm.notification.body", "body");
}

public Bundle asBundle() {
return (Bundle) mBundle.clone();
}

public boolean isFirebaseBackgroundPayload() {
return mBundle.containsKey("google.message_id") && !mBundle.containsKey("title");
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder(1024);
Expand All @@ -34,4 +38,9 @@ public String toString() {
protected PushNotificationProps copy() {
return new PushNotificationProps((Bundle) mBundle.clone());
}

private String getBundleStringFirstNotNull(String key1, String key2) {
String result = mBundle.getString(key1);
return result == null ? mBundle.getString(key2) : result;
}
}