Skip to content

Commit d235a03

Browse files
authored
Merge pull request #57576 from bernhardoj/fix/57205-gbr-shows-after-deleting-self-mention-action
Fix GBR still shows when mark report as unread after deleting mention action
2 parents 27fafd0 + e695bdb commit d235a03

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/libs/actions/Report.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,10 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) {
16371637
if (didCommentMentionCurrentUser && reportAction.created === report?.lastMentionedTime) {
16381638
const reportActionsForReport = allReportActions?.[reportID];
16391639
const latestMentioneReportAction = Object.values(reportActionsForReport ?? {}).find(
1640-
(action) => action.reportActionID !== reportAction.reportActionID && ReportActionsUtils.didMessageMentionCurrentUser(action),
1640+
(action) =>
1641+
action.reportActionID !== reportAction.reportActionID &&
1642+
ReportActionsUtils.didMessageMentionCurrentUser(action) &&
1643+
ReportActionsUtils.shouldReportActionBeVisible(action, action.reportActionID),
16411644
);
16421645
optimisticReport.lastMentionedTime = latestMentioneReportAction?.created ?? null;
16431646
}

tests/actions/ReportTest.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import * as SequentialQueue from '@src/libs/Network/SequentialQueue';
1818
import * as ReportUtils from '@src/libs/ReportUtils';
1919
import ONYXKEYS from '@src/ONYXKEYS';
2020
import type * as OnyxTypes from '@src/types/onyx';
21+
import createRandomReportAction from '../utils/collections/reportActions';
22+
import createRandomReport from '../utils/collections/reports';
2123
import getIsUsingFakeTimers from '../utils/getIsUsingFakeTimers';
2224
import PusherHelper from '../utils/PusherHelper';
2325
import * as TestHelper from '../utils/TestHelper';
@@ -1436,4 +1438,51 @@ describe('actions/Report', () => {
14361438

14371439
TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1);
14381440
});
1441+
1442+
it('should clears lastMentionedTime when all mentions to the current user are deleted', async () => {
1443+
const reportID = '1';
1444+
const mentionActionID = '1';
1445+
const mentionActionID2 = '2';
1446+
const currentUserAccountID = 123;
1447+
1448+
const mentionAction = {
1449+
...createRandomReportAction(Number(mentionActionID)),
1450+
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
1451+
originalMessage: {
1452+
mentionedAccountIDs: [currentUserAccountID],
1453+
},
1454+
} as OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT>;
1455+
1456+
const mentionAction2 = {
1457+
...createRandomReportAction(Number(mentionActionID2)),
1458+
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
1459+
originalMessage: {
1460+
mentionedAccountIDs: [currentUserAccountID],
1461+
},
1462+
} as OnyxTypes.ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT>;
1463+
1464+
await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID});
1465+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {
1466+
[mentionActionID]: mentionAction,
1467+
[mentionActionID2]: mentionAction2,
1468+
});
1469+
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
1470+
...createRandomReport(Number(reportID)),
1471+
lastMentionedTime: mentionAction2.created,
1472+
});
1473+
1474+
Report.deleteReportComment(reportID, mentionAction);
1475+
Report.deleteReportComment(reportID, mentionAction2);
1476+
1477+
await waitForBatchedUpdates();
1478+
1479+
const report = await new Promise<OnyxEntry<OnyxTypes.Report>>((resolve) => {
1480+
Onyx.connect({
1481+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1482+
callback: resolve,
1483+
});
1484+
});
1485+
1486+
expect(report?.lastMentionedTime).toBeUndefined();
1487+
});
14391488
});

0 commit comments

Comments
 (0)