diff --git a/src/libs/Navigation/Navigation.js b/src/libs/Navigation/Navigation.js index 167f2d9eea96..c4e25b6288c8 100644 --- a/src/libs/Navigation/Navigation.js +++ b/src/libs/Navigation/Navigation.js @@ -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 ''; } diff --git a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.js b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.js index 905397da1738..5c3d37ff9c92 100644 --- a/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.js +++ b/src/libs/Notification/PushNotification/subscribeToReportCommentPushNotifications.js @@ -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'; @@ -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}); + } + }); }); }