Skip to content

Commit

Permalink
Merge pull request #41484 from wildan-m/wildan/fix-34829-mark-message…
Browse files Browse the repository at this point in the history
…-from-notification
  • Loading branch information
blimpich authored May 13, 2024
2 parents 5aa12fa + 1ad9964 commit 5627349
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4750,6 +4750,10 @@ const CONST = {
SEARCH_DATA_TYPES: {
TRANSACTION: 'transaction',
},

REFERRER: {
NOTIFICATION: 'notification',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
6 changes: 5 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ const ROUTES = {
REPORT: 'r',
REPORT_WITH_ID: {
route: 'r/:reportID?/:reportActionID?',
getRoute: (reportID: string, reportActionID?: string) => (reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const)),
getRoute: (reportID: string, reportActionID?: string, referrer?: string) => {
const baseRoute = reportActionID ? (`r/${reportID}/${reportActionID}` as const) : (`r/${reportID}` as const);
const referrerParam = referrer ? `?referrer=${encodeURIComponent(referrer)}` : '';
return `${baseRoute}${referrerParam}` as const;
},
},
REPORT_AVATAR: {
route: 'r/:reportID/avatar',
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type CentralPaneNavigatorParamList = {
reportActionID: string;
reportID: string;
openOnAdminRoom?: boolean;
referrer?: string;
};
[SCREENS.SETTINGS.PROFILE.ROOT]: undefined;
[SCREENS.SETTINGS.PREFERENCES.ROOT]: undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CachedPDFPaths from './CachedPDFPaths';
import * as Modal from './Modal';
import navigateFromNotification from './navigateFromNotification';
import * as Session from './Session';
import * as Welcome from './Welcome';

Expand Down Expand Up @@ -2302,7 +2303,7 @@ function showReportActionNotification(reportID: string, reportAction: ReportActi
if (!reportBelongsToWorkspace) {
Navigation.navigateWithSwitchPolicyID({route: ROUTES.HOME});
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID));
navigateFromNotification(reportID);
});

if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.MODIFIED_EXPENSE) {
Expand Down
9 changes: 9 additions & 0 deletions src/libs/actions/navigateFromNotification/index.desktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

const navigateFromNotification = (reportID: string) => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID, undefined, CONST.REFERRER.NOTIFICATION));
};

export default navigateFromNotification;
8 changes: 8 additions & 0 deletions src/libs/actions/navigateFromNotification/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';

const navigateFromNotification = (reportID: string) => {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(reportID));
};

export default navigateFromNotification;
8 changes: 6 additions & 2 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,14 @@ function ReportActionsList({
if (!userActiveSince.current || report.reportID !== prevReportID) {
return;
}

if (ReportUtils.isUnread(report)) {
if (Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) {
// On desktop, when the notification center is displayed, Visibility.isVisible() will return false.
// Currently, there's no programmatic way to dismiss the notification center panel.
// To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
const isFromNotification = route?.params?.referrer === CONST.REFERRER.NOTIFICATION;
if ((Visibility.isVisible() || isFromNotification) && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) {
Report.readNewestAction(report.reportID);
Navigation.setParams({referrer: undefined});
} else {
readActionSkipped.current = true;
}
Expand Down

0 comments on commit 5627349

Please sign in to comment.