Skip to content

Commit 5c5c862

Browse files
authored
Merge pull request #32958 from dukenv0307/fix/31748
Mark the latest report action from other users as unread
2 parents d34b673 + d46864d commit 5c5c862

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libs/actions/Report.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,18 @@ function readNewestAction(reportID: string) {
938938
* Sets the last read time on a report
939939
*/
940940
function markCommentAsUnread(reportID: string, reportActionCreated: string) {
941-
// If no action created date is provided, use the last action's
942-
const actionCreationTime = reportActionCreated || (allReports?.[reportID]?.lastVisibleActionCreated ?? DateUtils.getDBTime(0));
941+
const reportActions = allReportActions?.[reportID];
942+
943+
// Find the latest report actions from other users
944+
const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => {
945+
if (current.actorAccountID !== currentUserAccountID && (!latest || current.created > latest.created)) {
946+
return current;
947+
}
948+
return latest;
949+
}, null);
950+
951+
// If no action created date is provided, use the last action's from other user
952+
const actionCreationTime = reportActionCreated || (latestReportActionFromOtherUsers?.created ?? DateUtils.getDBTime(0));
943953

944954
// We subtract 1 millisecond so that the lastReadTime is updated to just before a given reportAction's created date
945955
// For example, if we want to mark a report action with ID 100 and created date '2014-04-01 16:07:02.999' unread, we set the lastReadTime to '2014-04-01 16:07:02.998'

0 commit comments

Comments
 (0)