Skip to content

Commit

Permalink
Merge pull request #14588 from tienifr/fix/13691
Browse files Browse the repository at this point in the history
Update use of allPolicies variable and push notification subscription to fix inconsistency in deep link routing
  • Loading branch information
Julesssss authored Jan 31, 2023
2 parents f624d82 + f2a52fc commit 804a97c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/libs/Notification/PushNotification/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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();
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
});
}
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/libs/actions/Welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 804a97c

Please sign in to comment.