Skip to content

Commit

Permalink
Kill ReconnectToReport
Browse files Browse the repository at this point in the history
  • Loading branch information
aldo-expensify committed Jan 22, 2024
1 parent 5e71037 commit 404732f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 86 deletions.
59 changes: 0 additions & 59 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,58 +767,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,
},
},
];

type ReconnectToReportParameters = {
reportID: string;
};

const parameters: ReconnectToReportParameters = {
reportID,
};

API.write('ReconnectToReport', 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 @@ -1095,12 +1043,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);
}
}

Onyx.connect({
Expand Down Expand Up @@ -2654,7 +2596,6 @@ export {
searchInServer,
addComment,
addAttachment,
reconnect,
updateWelcomeMessage,
updateWriteCapabilityAndNavigate,
updateNotificationPreference,
Expand Down
29 changes: 2 additions & 27 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ function ReportActionsView(props) {
const isFirstRender = useRef(true);
const hasCachedActions = useInitialValue(() => _.size(props.reportActions) > 0);
const mostRecentIOUReportActionID = useInitialValue(() => ReportActionsUtils.getMostRecentIOURequestActionID(props.reportActions));

const prevNetworkRef = useRef(props.network);
const prevAuthTokenType = usePrevious(props.session.authTokenType);

const prevIsSmallScreenWidthRef = useRef(props.isSmallScreenWidth);

const isFocused = useIsFocused();
Expand All @@ -118,36 +115,14 @@ function ReportActionsView(props) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

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 = lodashGet(prevNetwork, 'isOffline') && !lodashGet(props.network, 'isOffline');
if (wasNetworkChangeDetected) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
Report.reconnect(reportID);
}
}
// update ref with current network state
prevNetworkRef.current = props.network;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.network, props.report, isReportFullyVisible]);

useEffect(() => {
const wasLoginChangedDetected = prevAuthTokenType === 'anonymousAccount' && !props.session.authTokenType;
if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(props.report)) {
if (isReportFullyVisible) {
openReportIfNecessary();
} else {
Report.reconnect(reportID);
}
openReportIfNecessary();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.session, props.report, isReportFullyVisible]);

}, [props.session, props.report]);
useEffect(() => {
const prevIsSmallScreenWidth = prevIsSmallScreenWidthRef.current;
// If the view is expanded from mobile to desktop layout
Expand Down

0 comments on commit 404732f

Please sign in to comment.