Skip to content

Commit

Permalink
Merge pull request #21257 from Expensify/arosiclair-notification-clic…
Browse files Browse the repository at this point in the history
…k-through

Fix push notification click through
  • Loading branch information
Julesssss authored Jun 27, 2023
2 parents e5f00f8 + b103132 commit 9604ac7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ function dismissModal(targetReportID) {
* @returns {String}
*/
function getActiveRoute() {
const currentRouteHasName = navigationRef.current && navigationRef.current.getCurrentRoute().name;
const currentRoute = navigationRef.current && navigationRef.current.getCurrentRoute();
const currentRouteHasName = lodashGet(currentRoute, 'name', false);
if (!currentRouteHasName) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {Linking} from 'react-native';
import Onyx from 'react-native-onyx';
import CONST from '../../../CONST';
import PushNotification from '.';
import ROUTES from '../../../ROUTES';
import Log from '../../Log';
Expand All @@ -10,23 +8,30 @@ import Navigation from '../../Navigation/Navigation';
* Setup reportComment push notification callbacks.
*/
export default function subscribeToReportCommentPushNotifications() {
PushNotification.onReceived(PushNotification.TYPE.REPORT_COMMENT, ({reportID, onyxData}) => {
Log.info('[Report] Handled event sent by Airship', false, {reportID});
PushNotification.onReceived(PushNotification.TYPE.REPORT_COMMENT, ({reportID, reportActionID, onyxData}) => {
Log.info('[PushNotification] Handled event sent by Airship', false, {reportID, reportActionID});
Onyx.update(onyxData);
});

// Open correct report when push notification is clicked
PushNotification.onSelected(PushNotification.TYPE.REPORT_COMMENT, ({reportID}) => {
if (Navigation.canNavigate('navigate')) {
// If a chat is visible other than the one we are trying to navigate to, then we need to navigate back
if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) {
Navigation.goBack();
}
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)}`);
PushNotification.onSelected(PushNotification.TYPE.REPORT_COMMENT, ({reportID, reportActionID}) => {
if (!reportID) {
Log.warn('[PushNotification] This push notification has no reportID');
}

Log.info('[PushNotification] onSelected() - called', false, {reportID, reportActionID});
Navigation.isNavigationReady().then(() => {
try {
// If a chat is visible other than the one we are trying to navigate to, then we need to navigate back
if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) {
Navigation.goBack();
}

Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID, reportActionID});
Navigation.navigate(ROUTES.getReportRoute(reportID));
} catch (error) {
Log.alert('[PushNotification] onSelected() - failed', {reportID, reportActionID, error: error.message});
}
});
});
}

0 comments on commit 9604ac7

Please sign in to comment.