Fix race condition when opening the app from push notification (#1898)

This commit is contained in:
Elias Nahum 2018-07-09 16:15:50 -04:00 committed by GitHub
parent 3a2e8e256a
commit 91a4abbd24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,8 +48,18 @@ const onRegisterDevice = (data) => {
}
};
const loadFromNotification = async (notification) => {
await store.dispatch(loadFromPushNotification(notification));
if (!app.startAppFromPushNotification) {
EventEmitter.emit(ViewTypes.NOTIFICATION_TAPPED);
PushNotifications.resetNotification();
}
};
const onPushNotification = async (deviceNotification) => {
const {dispatch, getState} = store;
let unsubscribeFromStore = null;
let stopLoadingNotification = false;
// mark the app as started as soon as possible
if (Platform.OS === 'android' && !app.appStarted) {
@ -77,11 +87,17 @@ const onPushNotification = async (deviceNotification) => {
} else if (userInteraction && !notification.localNotification) {
EventEmitter.emit('close_channel_drawer');
if (getState().views.root.hydrationComplete) {
await dispatch(loadFromPushNotification(notification));
if (!app.startAppFromPushNotification) {
EventEmitter.emit(ViewTypes.NOTIFICATION_TAPPED);
PushNotifications.resetNotification();
}
loadFromNotification(notification);
} else {
const waitForHydration = () => {
if (getState().views.root.hydrationComplete && !stopLoadingNotification) {
stopLoadingNotification = true;
unsubscribeFromStore();
loadFromNotification(notification);
}
};
unsubscribeFromStore = store.subscribe(waitForHydration);
}
}
}