Skip to content

Commit

Permalink
Merge pull request #34902 from Expensify/aldo_remove-reconnect-report
Browse files Browse the repository at this point in the history
HIGH: Kill ReconnectToReport
  • Loading branch information
aldo-expensify authored Apr 3, 2024
2 parents 6abecc8 + 5c587e0 commit 6463de6
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 97 deletions.
5 changes: 0 additions & 5 deletions src/libs/API/parameters/ReconnectToReportParams.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export type {default as VerifyIdentityForBankAccountParams} from './VerifyIdenti
export type {default as AnswerQuestionsForWalletParams} from './AnswerQuestionsForWalletParams';
export type {default as AddCommentOrAttachementParams} from './AddCommentOrAttachementParams';
export type {default as OptInOutToPushNotificationsParams} from './OptInOutToPushNotificationsParams';
export type {default as ReconnectToReportParams} from './ReconnectToReportParams';
export type {default as ReadNewestActionParams} from './ReadNewestActionParams';
export type {default as MarkAsUnreadParams} from './MarkAsUnreadParams';
export type {default as TogglePinnedChatParams} from './TogglePinnedChatParams';
Expand Down
2 changes: 0 additions & 2 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const WRITE_COMMANDS = {
RESTART_BANK_ACCOUNT_SETUP: 'RestartBankAccountSetup',
OPT_IN_TO_PUSH_NOTIFICATIONS: 'OptInToPushNotifications',
OPT_OUT_OF_PUSH_NOTIFICATIONS: 'OptOutOfPushNotifications',
RECONNECT_TO_REPORT: 'ReconnectToReport',
READ_NEWEST_ACTION: 'ReadNewestAction',
MARK_AS_UNREAD: 'MarkAsUnread',
TOGGLE_PINNED_CHAT: 'TogglePinnedChat',
Expand Down Expand Up @@ -272,7 +271,6 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.RESTART_BANK_ACCOUNT_SETUP]: Parameters.RestartBankAccountSetupParams;
[WRITE_COMMANDS.OPT_IN_TO_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
[WRITE_COMMANDS.OPT_OUT_OF_PUSH_NOTIFICATIONS]: Parameters.OptInOutToPushNotificationsParams;
[WRITE_COMMANDS.RECONNECT_TO_REPORT]: Parameters.ReconnectToReportParams;
[WRITE_COMMANDS.READ_NEWEST_ACTION]: Parameters.ReadNewestActionParams;
[WRITE_COMMANDS.MARK_AS_UNREAD]: Parameters.MarkAsUnreadParams;
[WRITE_COMMANDS.TOGGLE_PINNED_CHAT]: Parameters.TogglePinnedChatParams;
Expand Down
56 changes: 0 additions & 56 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type {
OpenReportParams,
OpenRoomMembersPageParams,
ReadNewestActionParams,
ReconnectToReportParams,
RemoveEmojiReactionParams,
RemoveFromRoomParams,
ResolveActionableMentionWhisperParams,
Expand Down Expand Up @@ -888,54 +887,6 @@ function navigateToAndOpenChildReport(childReportID = '0', parentReportAction: P
}
}

/** Get the latest report history without marking the report as read. */
function reconnect(reportID: string) {
const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
reportName: allReports?.[reportID]?.reportName ?? CONST.REPORT.DEFAULT_REPORT_NAME,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingInitialReportActions: true,
isLoadingNewerReportActions: false,
isLoadingOlderReportActions: false,
},
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingInitialReportActions: false,
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`,
value: {
isLoadingInitialReportActions: false,
},
},
];

const parameters: ReconnectToReportParams = {
reportID,
};

API.write(WRITE_COMMANDS.RECONNECT_TO_REPORT, parameters, {optimisticData, successData, failureData});
}

/**
* Gets the older actions that have not been read yet.
* Normally happens when you scroll up on a chat, and the actions have not been read yet.
Expand Down Expand Up @@ -1182,12 +1133,6 @@ function handleReportChanged(report: OnyxEntry<Report>) {
conciergeChatReportID = report.reportID;
}
}

// A report can be missing a name if a comment is received via pusher event and the report does not yet exist in Onyx (eg. a new DM created with the logged in person)
// In this case, we call reconnect so that we can fetch the report data without marking it as read
if (report.reportID && report.reportName === undefined) {
reconnect(report.reportID);
}
}

/** Deletes a comment from the report, basically sets it as empty string */
Expand Down Expand Up @@ -3031,7 +2976,6 @@ export {
searchInServer,
addComment,
addAttachment,
reconnect,
updateDescription,
updateWriteCapabilityAndNavigate,
updateNotificationPreference,
Expand Down
35 changes: 2 additions & 33 deletions src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function ReportActionsView({
const {isSmallScreenWidth, windowHeight} = useWindowDimensions();
const contentListHeight = useRef(0);
const isFocused = useIsFocused();
const prevNetworkRef = useRef(network);
const prevAuthTokenType = usePrevious(session?.authTokenType);
const [isNavigatingToLinkedMessage, setNavigatingToLinkedMessage] = useState(!!reportActionID);
const prevIsSmallScreenWidthRef = useRef(isSmallScreenWidth);
Expand All @@ -119,14 +118,6 @@ function ReportActionsView({
Report.openReport(reportID, reportActionID);
};

const reconnectReportIfNecessary = () => {
if (!shouldFetchReport(report)) {
return;
}

Report.reconnect(reportID);
};

useLayoutEffect(() => {
setCurrentReportActionID('');
}, [route]);
Expand Down Expand Up @@ -273,35 +264,13 @@ function ReportActionsView({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [route, indexOfLinkedAction]);

useEffect(() => {
const prevNetwork = prevNetworkRef.current;
// When returning from offline to online state we want to trigger a request to OpenReport which
// will fetch the reportActions data and mark the report as read. If the report is not fully visible
// then we call ReconnectToReport which only loads the reportActions data without marking the report as read.
const wasNetworkChangeDetected = prevNetwork.isOffline && !network.isOffline;
if (wasNetworkChangeDetected) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
reconnectReportIfNecessary();
}
}
// update ref with current network state
prevNetworkRef.current = network;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [network, isReportFullyVisible]);

useEffect(() => {
const wasLoginChangedDetected = prevAuthTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS && !session?.authTokenType;
if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(report)) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
reconnectReportIfNecessary();
}
openReportIfNecessary();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [session, report, isReportFullyVisible]);
}, [session, report]);

useEffect(() => {
const prevIsSmallScreenWidth = prevIsSmallScreenWidthRef.current;
Expand Down

0 comments on commit 6463de6

Please sign in to comment.