Skip to content

Commit

Permalink
Merge pull request #43742 from nkdengineer/fix/41645
Browse files Browse the repository at this point in the history
fix: display thread of send money request as normal thread
  • Loading branch information
stitesExpensify authored Jun 27, 2024
2 parents 24b7c48 + d68624b commit d136101
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Onyx.connect({
const transactionThreadReportID = ReportActionUtils.getOneTransactionThreadReportID(reportID, actions[reportActions[0]]);
if (transactionThreadReportID) {
const transactionThreadReportActionsArray = Object.values(actions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`] ?? {});
sortedReportActions = ReportActionUtils.getCombinedReportActions(reportActionsArray, transactionThreadReportID, transactionThreadReportActionsArray, reportID);
sortedReportActions = ReportActionUtils.getCombinedReportActions(sortedReportActions, transactionThreadReportID, transactionThreadReportActionsArray, reportID);
}

lastReportActions[reportID] = sortedReportActions[0];
Expand Down
11 changes: 7 additions & 4 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,14 @@ function getCombinedReportActions(
transactionThreadReportActions: ReportAction[],
reportID?: string,
): ReportAction[] {
if (_.isEmpty(transactionThreadReportID)) {
const isSentMoneyReport = reportActions.some((action) => isSentMoneyReportAction(action));

// We don't want to combine report actions of transaction thread in iou report of send money request because we display the transaction report of send money request as a normal thread
if (_.isEmpty(transactionThreadReportID) || isSentMoneyReport) {
return reportActions;
}

// Filter out the created action from the transaction thread report actions, since we already have the parent report's created action in `reportActions`
// Filter out request money actions because we don't want to show any preview actions for one transaction reports
const filteredTransactionThreadReportActions = transactionThreadReportActions?.filter((action) => action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED);
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const isSelfDM = report?.chatType === CONST.REPORT.CHAT_TYPE.SELF_DM;
Expand All @@ -398,9 +401,9 @@ function getCombinedReportActions(
}
const actionType = getOriginalMessage(action)?.type ?? '';
if (isSelfDM) {
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && !isSentMoneyReportAction(action);
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE;
}
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK && !isSentMoneyReportAction(action);
return actionType !== CONST.IOU.REPORT_ACTION_TYPE.CREATE && actionType !== CONST.IOU.REPORT_ACTION_TYPE.TRACK;
});

return getSortedReportActions(filteredReportActions, true);
Expand Down
12 changes: 9 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ function getTransactionReportName(reportAction: OnyxEntry<ReportAction | Optimis
return Localize.translateLocal('iou.threadTrackReportName', {formattedAmount, comment});
}
if (ReportActionsUtils.isSentMoneyReportAction(reportAction)) {
return Localize.translateLocal('iou.threadPaySomeoneReportName', {formattedAmount, comment});
return getIOUReportActionDisplayMessage(reportAction as ReportAction, transaction);
}
return Localize.translateLocal('iou.threadExpenseReportName', {formattedAmount, comment});
}
Expand Down Expand Up @@ -6647,7 +6647,11 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto
const parentReport = getReportOrDraftReport(parentReportID);
const parentReportAction = ReportActionsUtils.getReportAction(parentReportID, parentReportActionID ?? '-1');

if (!parentReportAction || ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)) {
if (
!parentReportAction ||
(ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isSentMoneyReportAction(parentReportAction)) ||
ReportActionsUtils.isReportPreviewAction(parentReportAction)
) {
break;
}

Expand Down Expand Up @@ -6693,7 +6697,9 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ

if (
!parentReportAction ||
(!includeTransactionThread && (ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isReportPreviewAction(parentReportAction)))
(!includeTransactionThread &&
((ReportActionsUtils.isTransactionThread(parentReportAction) && !ReportActionsUtils.isSentMoneyReportAction(parentReportAction)) ||
ReportActionsUtils.isReportPreviewAction(parentReportAction)))
) {
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ function ReportActionItem({
// For the pay flow, we only want to show MoneyRequestAction when sending money. When paying, we display a regular system message
(ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK ||
isSendingMoney)
ReportActionsUtils.getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK)
) {
// There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID
const iouReportID = ReportActionsUtils.getOriginalMessage(action)?.IOUReportID ? ReportActionsUtils.getOriginalMessage(action)?.IOUReportID?.toString() ?? '-1' : '-1';
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ function ReportActionsListItemRenderer({
parentReportActionForTransactionThread,
}: ReportActionsListItemRendererProps) {
const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && ReportUtils.isChatThread(report) && !ReportActionsUtils.isTransactionThread(parentReportAction);
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED &&
ReportUtils.isChatThread(report) &&
(!ReportActionsUtils.isTransactionThread(parentReportAction) || ReportActionsUtils.isSentMoneyReportAction(parentReportAction));

/**
* Create a lightweight ReportAction so as to keep the re-rendering as light as possible by
Expand Down

0 comments on commit d136101

Please sign in to comment.