Skip to content
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

Update use of allPolicies variable and push notification subscription to fix inconsistency in deep link routing #14588

Merged
merged 5 commits into from
Jan 31, 2023
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
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