diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 94b5def18108..1945693cf289 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -425,6 +425,16 @@ function removeOptimisticActions(reportID) { }); } +/** + * @param {Number} reportID + * @param {Number} sequenceNumber + */ +function setNewMarkerPosition(reportID, sequenceNumber) { + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { + newMarkerSequenceNumber: sequenceNumber, + }); +} + /** * Updates a report action's message to be a new value. * @@ -530,6 +540,14 @@ function updateReportWithNewAction(reportID, reportAction) { if (lodashGet(reportAction, 'actorEmail') === 'concierge@expensify.com') { return; } + + // When a new message comes in, if the New marker is not already set (newMarkerSequenceNumber === 0), set the + // marker above the incoming message. + if (lodashGet(allReports, [reportID, 'newMarkerSequenceNumber'], 0) === 0 + && updatedReportObject.unreadActionCount > 0) { + const oldestUnreadSeq = (updatedReportObject.maxSequenceNumber - updatedReportObject.unreadActionCount) + 1; + setNewMarkerPosition(reportID, oldestUnreadSeq); + } console.debug('[LOCAL_NOTIFICATION] Creating notification'); LocalNotification.showCommentNotification({ reportAction, @@ -996,16 +1014,6 @@ function updateLastReadActionID(reportID, sequenceNumber) { }); } -/** - * @param {Number} reportID - * @param {Number} sequenceNumber - */ -function setNewMarkerPosition(reportID, sequenceNumber) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { - newMarkerSequenceNumber: sequenceNumber, - }); -} - /** * Toggles the pinned state of the report. *