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 mark message from notification #41484

Merged
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
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 @@ -209,7 +209,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 @@ -2296,7 +2297,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 @@ -249,10 +249,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from this issue
In most cases, Visibility.isVisible() returns the value that the app is not visible (inactive). It happens because of the leverage of outdated value.
As result chat is not marked as read (chat is bold) on LHN when opening a new message via notification and navigating to another chat.

So the more preferable value is to use isVisible in this screen

Report.readNewestAction(report.reportID);
Navigation.setParams({referrer: undefined});
Comment on lines +257 to +259
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from #45093 we should only set navigation param referrer to undefined when user is linked through notification

} else {
readActionSkipped.current = true;
}
Expand Down
Loading