Skip to content

Commit

Permalink
Revert "Merge pull request #34537 from FitseTLT/fix-mark-as-read-on-v…
Browse files Browse the repository at this point in the history
…isibility-change"

This reverts commit 77814e5, reversing
changes made to b0e2a92.
  • Loading branch information
mountiny committed Jan 29, 2024
1 parent 7528e8d commit c472590
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 50 deletions.
7 changes: 1 addition & 6 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,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 @@ -948,11 +948,6 @@ function readNewestAction(reportID: string, shouldEmitEvent = true) {
};

API.write(WRITE_COMMANDS.READ_NEWEST_ACTION, parameters, {optimisticData});

if (!shouldEmitEvent) {
return;
}

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 c472590

Please sign in to comment.