Skip to content
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
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});
}
});
});
}