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

Fix push notification click through #21257

Merged
merged 7 commits into from
Jun 27, 2023
Merged
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});
}
});
});
}