Skip to content

Commit

Permalink
Merge pull request #35308 from Expensify/vit-revert34537
Browse files Browse the repository at this point in the history
[CP Staging] Revert "Merge pull request #34537 from FitseTLT/fix-mark-as-read-on-v…

(cherry picked from commit b2e1e21)
  • Loading branch information
pecanoro authored and OSBotify committed Jan 29, 2024
1 parent a6f0fd3 commit 6fc4a5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
6 changes: 5 additions & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ function expandURLPreview(reportID: string, reportActionID: string) {
}

/** Marks the new report actions as read */
function readNewestAction(reportID: string, shouldEmitEvent = true) {
function readNewestAction(reportID: string) {
const lastReadTime = DateUtils.getDBTime();

const optimisticData: OnyxUpdate[] = [
Expand All @@ -957,12 +957,16 @@ function readNewestAction(reportID: string, shouldEmitEvent = true) {
lastReadTime,
};

<<<<<<< HEAD
API.write('ReadNewestAction', parameters, {optimisticData});

if (!shouldEmitEvent) {
return;
}

=======
API.write(WRITE_COMMANDS.READ_NEWEST_ACTION, parameters, {optimisticData});
>>>>>>> b2e1e21 (Merge pull request #35308 from Expensify/vit-revert34537)
DeviceEventEmitter.emit(`readNewestAction_${reportID}`, lastReadTime);
}

Expand Down
46 changes: 2 additions & 44 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ function ReportActionsList({
const route = useRoute();
const opacity = useSharedValue(0);
const userActiveSince = useRef(null);
const userInactiveSince = useRef(null);

const markerInit = () => {
if (!cacheUnreadMarkers.has(report.reportID)) {
Expand Down Expand Up @@ -388,7 +387,7 @@ function ReportActionsList({
[currentUnreadMarker, sortedVisibleReportActions, report.reportID, messageManuallyMarkedUnread],
);

const calculateUnreadMarker = useCallback(() => {
useEffect(() => {
// Iterate through the report actions and set appropriate unread marker.
// This is to avoid a warning of:
// Cannot update a component (ReportActionsList) while rendering a different component (CellRenderer).
Expand All @@ -406,48 +405,7 @@ function ReportActionsList({
if (!markerFound) {
setCurrentUnreadMarker(null);
}
}, [sortedVisibleReportActions, shouldDisplayNewMarker, currentUnreadMarker, report.reportID]);

useEffect(() => {
calculateUnreadMarker();
}, [calculateUnreadMarker, report.lastReadTime, messageManuallyMarkedUnread]);

const onVisibilityChange = useCallback(() => {
if (!Visibility.isVisible()) {
userInactiveSince.current = DateUtils.getDBTime();
return;
}
// In case the user read new messages (after being inactive) with other device we should
// show marker based on report.lastReadTime
const newMessageTimeReference = userInactiveSince.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime;
if (
scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD ||
!(
sortedVisibleReportActions &&
_.some(
sortedVisibleReportActions,
(reportAction) =>
newMessageTimeReference < reportAction.created &&
(ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID(),
)
)
) {
return;
}

Report.readNewestAction(report.reportID, false);
userActiveSince.current = DateUtils.getDBTime();
lastReadTimeRef.current = newMessageTimeReference;
setCurrentUnreadMarker(null);
cacheUnreadMarkers.delete(report.reportID);
calculateUnreadMarker();
}, [calculateUnreadMarker, report, sortedVisibleReportActions]);

useEffect(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(onVisibilityChange);

return unsubscribeVisibilityListener;
}, [onVisibilityChange]);
}, [sortedVisibleReportActions, report.lastReadTime, report.reportID, messageManuallyMarkedUnread, shouldDisplayNewMarker, currentUnreadMarker]);

const renderItem = useCallback(
({item: reportAction, index}) => (
Expand Down

0 comments on commit 6fc4a5e

Please sign in to comment.