From 8b105f7875534dad102278f72c52b49ed379e94d Mon Sep 17 00:00:00 2001 From: Rajat Parashar Date: Wed, 24 Nov 2021 21:24:49 +0530 Subject: [PATCH] fix: newline via updating the count first before marking the messages read --- src/libs/actions/Report.js | 3 ++- src/pages/home/report/ReportActionsView.js | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 57c9d7ec9fe9..f220bc6a4f4f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -573,7 +573,8 @@ function updateReportWithNewAction( reportID, // Use updated lastReadSequenceNumber, value may have been modified by setLocalLastRead - unreadActionCount: newMaxSequenceNumber - (lastReadSequenceNumbers[reportID] || 0), + // Here deletedComments count does not include the new action being added. We can safely assume that newly received action is not deleted. + unreadActionCount: newMaxSequenceNumber - (lastReadSequenceNumbers[reportID] || 0) - ReportActions.getDeletedCommentsCount(reportID, lastReadSequenceNumbers[reportID] || 0), maxSequenceNumber: reportAction.sequenceNumber, }; diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 8fef4adb920c..2c96f44c4659 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -145,12 +145,13 @@ class ReportActionsView extends React.Component { this.scrollToListBottom(); }); + this.updateUnreadIndicatorPosition(this.props.report.unreadActionCount); + // Only mark as read if the report is open if (!this.props.isDrawerOpen) { Report.updateLastReadActionID(this.props.reportID); } - this.updateUnreadIndicatorPosition(this.props.report.unreadActionCount); Report.fetchActions(this.props.reportID); } @@ -210,12 +211,6 @@ class ReportActionsView extends React.Component { this.scrollToListBottom(); } - // When the last action changes, record the max action - // This will make the unread indicator go away if you receive comments in the same chat you're looking at - if (shouldRecordMaxAction) { - Report.updateLastReadActionID(this.props.reportID); - } - if (lodashGet(lastAction, 'actorEmail', '') !== lodashGet(this.props.session, 'email', '')) { // Only update the unread count when MarkerBadge is visible // Otherwise marker will be shown on scrolling up from the bottom even if user have read those messages @@ -226,12 +221,18 @@ class ReportActionsView extends React.Component { // show new MarkerBadge when there is a new message this.toggleMarker(); } + + // When the last action changes, record the max action + // This will make the unread indicator go away if you receive comments in the same chat you're looking at + if (shouldRecordMaxAction) { + Report.updateLastReadActionID(this.props.reportID); + } } else if (shouldRecordMaxAction && ( prevProps.isDrawerOpen !== this.props.isDrawerOpen || prevProps.isSmallScreenWidth !== this.props.isSmallScreenWidth )) { - Report.updateLastReadActionID(this.props.reportID); this.updateUnreadIndicatorPosition(this.props.report.unreadActionCount); + Report.updateLastReadActionID(this.props.reportID); } }