Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ function readNewestAction(reportID: string) {
};

API.write('ReadNewestAction', parameters, {optimisticData});
DeviceEventEmitter.emit(`readNewestAction_${reportID}`, lastReadTime);
}

/**
Expand Down
26 changes: 16 additions & 10 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function ReportActionsList({
const route = useRoute();
const opacity = useSharedValue(0);
const userActiveSince = useRef(null);
const unreadActionSubscription = useRef(null);

const markerInit = () => {
if (!cacheUnreadMarkers.has(report.reportID)) {
return null;
Expand Down Expand Up @@ -236,20 +236,26 @@ function ReportActionsList({
}, [report.lastReadTime, report.reportID]);

useEffect(() => {
// If the reportID changes, we reset the userActiveSince to null, we need to do it because
// this component doesn't unmount when the reportID changes
Comment on lines -239 to -240

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this case the comment mentions, i.e. when the "reportID changes"?

I believe the changes you suggested are clean and improve the code, but I just want to be sure we don't introduce a regression, even when the intentions are pure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tested and make sure everything is ok. Can you help re-check?

if (unreadActionSubscription.current) {
unreadActionSubscription.current.remove();
unreadActionSubscription.current = null;
}

// Listen to specific reportID for unread event and set the marker to new message
unreadActionSubscription.current = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime) => {
const resetUnreadMarker = (newLastReadTime) => {
cacheUnreadMarkers.delete(report.reportID);
lastReadTimeRef.current = newLastReadTime;
setCurrentUnreadMarker(null);
};

const unreadActionSubscription = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime) => {
resetUnreadMarker(newLastReadTime);
setMessageManuallyMarkedUnread(new Date().getTime());
});

const readNewestActionSubscription = DeviceEventEmitter.addListener(`readNewestAction_${report.reportID}`, (newLastReadTime) => {
resetUnreadMarker(newLastReadTime);
setMessageManuallyMarkedUnread(0);
});

return () => {
unreadActionSubscription.remove();
readNewestActionSubscription.remove();
};
}, [report.reportID]);

useEffect(() => {
Expand Down