Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linked message visibility in offline mode #42396

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3574,6 +3574,13 @@ function updateLastVisitTime(reportID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {lastVisitTime: DateUtils.getDBTime()});
}

function updateLoadingInitialReportAction(reportID: string) {
if (!ReportUtils.isValidReportIDFromPath(reportID)) {
return;
}
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {isLoadingInitialReportActions: false});
}

function clearNewRoomFormError() {
Onyx.set(ONYXKEYS.FORMS.NEW_ROOM_FORM, {
isLoading: false,
Expand Down Expand Up @@ -3814,5 +3821,6 @@ export {
leaveGroupChat,
removeFromGroupChat,
updateGroupChatMemberRoles,
updateLoadingInitialReportAction,
clearAvatarErrors,
};
14 changes: 11 additions & 3 deletions src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function ReportActionsView({
const didLayout = useRef(false);
const didLoadOlderChats = useRef(false);
const didLoadNewerChats = useRef(false);
const {isOffline} = useNetwork();

// triggerListID is used when navigating to a chat with messages loaded from LHN. Typically, these include thread actions, task actions, etc. Since these messages aren't the latest,we don't maintain their position and instead trigger a recalculation of their positioning in the list.
// we don't set currentReportActionID on initial render as linkedID as it should trigger visibleReportActions after linked message was positioned
Expand All @@ -129,6 +130,14 @@ function ReportActionsView({
Report.openReport(reportID, reportActionID);
};

useEffect(() => {
// When we linked to message - we do not need to wait for initial actions - they already exists
if (!reportActionID || !isOffline) {
return;
}
Report.updateLoadingInitialReportAction(report.reportID);
}, [isOffline, report.reportID, reportActionID]);

useLayoutEffect(() => {
setCurrentReportActionID('');
}, [route]);
Expand Down Expand Up @@ -200,7 +209,7 @@ function ReportActionsView({
*/
const fetchNewerAction = useCallback(
(newestReportAction: OnyxTypes.ReportAction) => {
if (isLoadingNewerReportActions || isLoadingInitialReportActions) {
if (isLoadingNewerReportActions || isLoadingInitialReportActions || (!!reportActionID && isOffline)) {
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand All @@ -217,7 +226,7 @@ function ReportActionsView({
Report.getNewerActions(reportID, newestReportAction.reportActionID);
}
},
[isLoadingNewerReportActions, isLoadingInitialReportActions, reportID, transactionThreadReport, reportActionIDMap],
[isLoadingNewerReportActions, isLoadingInitialReportActions, reportActionID, isOffline, transactionThreadReport, reportActionIDMap, reportID],
);

const hasMoreCached = reportActions.length < combinedReportActions.length;
Expand Down Expand Up @@ -372,7 +381,6 @@ function ReportActionsView({
// If there was an error only try again once on initial mount. We should also still load
// more in case we have cached messages.
(!hasMoreCached && didLoadNewerChats.current && hasLoadingNewerReportActionsError) ||
network.isOffline ||
newestReportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
) {
return;
Expand Down
Loading