Skip to content

Commit d2dc97c

Browse files
committed
Fix displaying unread marker correctly
1 parent 319e605 commit d2dc97c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

+25-2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
189189
}, [visibleReportActions]);
190190
const prevVisibleActionsMap = usePrevious(visibleActionsMap);
191191

192+
const reportLastReadTime = report.lastReadTime ?? '';
193+
192194
/**
193195
* The timestamp for the unread marker.
194196
*
@@ -197,9 +199,9 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
197199
* - marks a message as read/unread
198200
* - reads a new message as it is received
199201
*/
200-
const [unreadMarkerTime, setUnreadMarkerTime] = useState(report.lastReadTime);
202+
const [unreadMarkerTime, setUnreadMarkerTime] = useState(reportLastReadTime);
201203
useEffect(() => {
202-
setUnreadMarkerTime(report.lastReadTime);
204+
setUnreadMarkerTime(reportLastReadTime);
203205

204206
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
205207
}, [report.reportID]);
@@ -273,6 +275,27 @@ function MoneyRequestReportActionsList({report, reportActions = [], hasNewerActi
273275
};
274276
}, [report.reportID]);
275277

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+
276299
const scrollToBottomForCurrentUserAction = useCallback(
277300
(isFromCurrentUser: boolean) => {
278301
InteractionManager.runAfterInteractions(() => {

0 commit comments

Comments
 (0)