Skip to content

Commit

Permalink
Merge pull request Expensify#32958 from dukenv0307/fix/31748
Browse files Browse the repository at this point in the history
Mark the latest report action from other users as unread
  • Loading branch information
MonilBhavsar authored Dec 29, 2023
2 parents d34b673 + d46864d commit 5c5c862
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,18 @@ 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 actionCreationTime = reportActionCreated || (allReports?.[reportID]?.lastVisibleActionCreated ?? DateUtils.getDBTime(0));
const reportActions = allReportActions?.[reportID];

// Find the latest report actions from other users
const latestReportActionFromOtherUsers = Object.values(reportActions ?? {}).reduce((latest: ReportAction | null, current: ReportAction) => {
if (current.actorAccountID !== currentUserAccountID && (!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
// 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'
Expand Down

0 comments on commit 5c5c862

Please sign in to comment.