diff --git a/src/libs/Notification/PushNotification/index.native.js b/src/libs/Notification/PushNotification/index.native.js index b6787858191d..4dc3ad1c3a8e 100644 --- a/src/libs/Notification/PushNotification/index.native.js +++ b/src/libs/Notification/PushNotification/index.native.js @@ -4,6 +4,8 @@ import {UrbanAirship, EventType, iOS} from 'urbanairship-react-native'; import lodashGet from 'lodash/get'; import Log from '../../Log'; import NotificationType from './NotificationType'; +import PushNotification from '.'; +import * as Report from '../../actions/Report'; const notificationEventActionMap = {}; @@ -107,6 +109,12 @@ function register(accountID) { // Regardless of the user's opt-in status, we still want to receive silent push notifications. Log.info(`[PUSH_NOTIFICATIONS] Subscribing to notifications for account ID ${accountID}`); UrbanAirship.setNamedUser(accountID.toString()); + + // When the user logged out and then logged in with a different account + // while the app is still in background, we must resubscribe to the report + // push notification in order to render the report click behaviour correctly + PushNotification.init(); + Report.subscribeToReportCommentPushNotifications(); } /** diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 0bf3c384a5c1..7abb23497604 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -65,11 +65,17 @@ function subscribeToReportCommentPushNotifications() { if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) { Navigation.goBack(); } - Navigation.navigate(ROUTES.getReportRoute(reportID)); + Navigation.isDrawerReady() + .then(() => { + Navigation.navigate(ROUTES.getReportRoute(reportID)); + }); } else { // Navigation container is not yet ready, use deeplinking to open to correct report instead Navigation.setDidTapNotification(); - Linking.openURL(`${CONST.DEEPLINK_BASE_URL}${ROUTES.getReportRoute(reportID)}`); + Navigation.isDrawerReady() + .then(() => { + Linking.openURL(`${CONST.DEEPLINK_BASE_URL}${ROUTES.getReportRoute(reportID)}`); + }); } }); } diff --git a/src/libs/actions/Welcome.js b/src/libs/actions/Welcome.js index d1130b9450b2..58a760a50f63 100644 --- a/src/libs/actions/Welcome.js +++ b/src/libs/actions/Welcome.js @@ -69,7 +69,12 @@ const allPolicies = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, callback: (val, key) => { - if (!val || !key) { + if (!key) { + return; + } + + if (val === null || val === undefined) { + delete allPolicies[key]; return; }