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

One-expense-report old chat messages stays in chat and loads slowly #44473

Closed
Show file tree
Hide file tree
Changes from all 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
27 changes: 19 additions & 8 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,22 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
);
}

/**
* Returns filtered list for one transaction view
* Separated it from getCombinedReportActions, so it can be reused
*/
function getFilteredForOneTransactionView(reportActions: ReportAction[], isSelfDM = false): ReportAction[] {
const filteredReportActions = reportActions.filter((action) => {
const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
});

return filteredReportActions;
}

/**
* Returns a sorted and filtered list of report actions from a report and it's associated child
* transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view.
Expand All @@ -322,14 +338,7 @@ function getCombinedReportActions(reportActions: ReportAction[], transactionThre

const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
// Filter out request and send money request actions because we don't want to show any preview actions for one transaction reports
const filteredReportActions = [...reportActions, ...filteredTransactionThreadReportActions].filter((action) => {
const actionType = (action as OriginalMessageIOU).originalMessage?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
});
const filteredReportActions = getFilteredForOneTransactionView([...reportActions, ...filteredTransactionThreadReportActions], isSelfDM);

return getSortedReportActions(filteredReportActions, true);
}
Expand Down Expand Up @@ -877,6 +886,7 @@ function isTaskAction(reportAction: OnyxEntry<ReportAction>): boolean {
);
}

//maybe that?
/**
* Gets the reportID for the transaction thread associated with a report by iterating over the reportActions and identifying the IOU report actions.
* Returns a reportID if there is exactly one transaction thread for the report, and null otherwise.
Expand Down Expand Up @@ -1322,6 +1332,7 @@ export {
wasActionTakenByCurrentUser,
isResolvedActionTrackExpense,
isTripPreview,
getFilteredForOneTransactionView,
};

export type {LastVisibleMessage};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ function ReportActionItem({
<OfflineWithFeedback pendingAction={action.pendingAction}>
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
<>
{transactionCurrency !== report.currency && (
{!!transaction && transactionCurrency !== report.currency && (
<>
<MoneyReportView
report={report}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function ReportActionsView({
createdAction.pendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE;
}

return [...actions, createdAction];
return moneyRequestActions.length === 1 ? ReportActionsUtils.getFilteredForOneTransactionView([...actions, createdAction]) : [...actions, createdAction];
}, [reportActions, report, transactionThreadReport]);

// Comments have not loaded at all yet do nothing
Expand Down
Loading