From cd777131d8c3a843ab36fe866939b0915b58b1b3 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 13 Dec 2023 13:06:12 +0700 Subject: [PATCH 1/3] mark the latest report action from other users as unread --- src/libs/actions/Report.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index bea4ab8aed77..1f4592c6492e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -940,7 +940,20 @@ function readNewestAction(reportID: string) { */ function markCommentAsUnread(reportID: string, reportActionCreated: string) { // If no action created date is provided, use the last action's - const actionCreationTime = reportActionCreated || (allReports?.[reportID]?.lastVisibleActionCreated ?? DateUtils.getDBTime(0)); + const reportActions = allReportActions?.[reportID]; + + if (!reportActions) { + return; + } + + // Find the latest report actions from other users + const reportActionsFromOtherUsers = Object.values(reportActions).filter((action) => action.actorAccountID !== currentUserAccountID); + let latestReportActionFromOtherUsers: ReportAction | null = null; + if (reportActionsFromOtherUsers.length !== 0) { + latestReportActionFromOtherUsers = reportActionsFromOtherUsers.reduce((latest, current) => (latest.created > current.created ? latest : current), reportActionsFromOtherUsers[0]); + } + + const actionCreationTime = reportActionCreated || (latestReportActionFromOtherUsers?.created ?? DateUtils.getDBTime(0)); // We subtract 1 millisecond so that the lastReadTime is updated to just before a given reportAction's created date // 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' From 04ff7ae972a6159d3e6414d0d26071da440ab863 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Dec 2023 12:19:55 +0700 Subject: [PATCH 2/3] find the latest report action from other users --- src/libs/actions/Report.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1f4592c6492e..999aca0ab750 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -939,20 +939,19 @@ function readNewestAction(reportID: string) { * Sets the last read time on a report */ function markCommentAsUnread(reportID: string, reportActionCreated: string) { - // If no action created date is provided, use the last action's const reportActions = allReportActions?.[reportID]; - if (!reportActions) { - return; - } - // Find the latest report actions from other users - const reportActionsFromOtherUsers = Object.values(reportActions).filter((action) => action.actorAccountID !== currentUserAccountID); - let latestReportActionFromOtherUsers: ReportAction | null = null; - if (reportActionsFromOtherUsers.length !== 0) { - latestReportActionFromOtherUsers = reportActionsFromOtherUsers.reduce((latest, current) => (latest.created > current.created ? latest : current), reportActionsFromOtherUsers[0]); - } + const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { + if (current.actorAccountID !== currentUserAccountID) { + if (!latest || current.created > latest.created) { + return current; + } + } + return latest; + }, null); + // If no action created date is provided, use the last action's from other user const actionCreationTime = reportActionCreated || (latestReportActionFromOtherUsers?.created ?? DateUtils.getDBTime(0)); // We subtract 1 millisecond so that the lastReadTime is updated to just before a given reportAction's created date From d46864da883e4fcdf74c0933c324ea947774c307 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 27 Dec 2023 14:50:37 +0700 Subject: [PATCH 3/3] merge main --- src/libs/actions/Report.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index e3a5745874e7..1564d076b0e2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -942,10 +942,8 @@ function markCommentAsUnread(reportID: string, reportActionCreated: string) { // Find the latest report actions from other users const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => { - if (current.actorAccountID !== currentUserAccountID) { - if (!latest || current.created > latest.created) { - return current; - } + if (current.actorAccountID !== currentUserAccountID && (!latest || current.created > latest.created)) { + return current; } return latest; }, null);