@@ -189,6 +189,8 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
189
189
} , [ visibleReportActions ] ) ;
190
190
const prevVisibleActionsMap = usePrevious ( visibleActionsMap ) ;
191
191
192
+ const reportLastReadTime = report . lastReadTime ?? '' ;
193
+
192
194
/**
193
195
* The timestamp for the unread marker.
194
196
*
@@ -197,9 +199,9 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
197
199
* - marks a message as read/unread
198
200
* - reads a new message as it is received
199
201
*/
200
- const [ unreadMarkerTime , setUnreadMarkerTime ] = useState ( report . lastReadTime ) ;
202
+ const [ unreadMarkerTime , setUnreadMarkerTime ] = useState ( reportLastReadTime ) ;
201
203
useEffect ( ( ) => {
202
- setUnreadMarkerTime ( report . lastReadTime ) ;
204
+ setUnreadMarkerTime ( reportLastReadTime ) ;
203
205
204
206
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
205
207
} , [ report . reportID ] ) ;
@@ -273,6 +275,27 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
273
275
} ;
274
276
} , [ report . reportID ] ) ;
275
277
278
+ /**
279
+ * When the user reads a new message as it is received, we'll push the unreadMarkerTime down to the timestamp of
280
+ * the latest report action. When new report actions are received and the user is not viewing them (they're above
281
+ * the MSG_VISIBLE_THRESHOLD), the unread marker will display over those new messages rather than the initial
282
+ * lastReadTime.
283
+ */
284
+ useLayoutEffect ( ( ) => {
285
+ if ( unreadMarkerReportActionID ) {
286
+ return ;
287
+ }
288
+
289
+ const mostRecentReportActionCreated = lastAction ?. created ?? '' ;
290
+ if ( mostRecentReportActionCreated <= unreadMarkerTime ) {
291
+ return ;
292
+ }
293
+
294
+ setUnreadMarkerTime ( mostRecentReportActionCreated ) ;
295
+
296
+ // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
297
+ } , [ lastAction ?. created ] ) ;
298
+
276
299
const scrollToBottomForCurrentUserAction = useCallback (
277
300
( isFromCurrentUser : boolean ) => {
278
301
InteractionManager . runAfterInteractions ( ( ) => {
0 commit comments