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: display thread of send money request as normal thread #43742

Merged
merged 9 commits into from
Jun 27, 2024
8 changes: 4 additions & 4 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ function shouldIgnoreGap(currentReportAction: ReportAction | undefined, nextRepo
* transaction thread report in order to correctly display reportActions from both reports in the one-transaction report view.
*/
function getCombinedReportActions(reportActions: ReportAction[], transactionThreadReportActions: ReportAction[], reportID?: string): ReportAction[] {
if (isEmptyObject(transactionThreadReportActions)) {
if (isEmptyObject(transactionThreadReportActions) || reportActions.some((action) => isSentMoneyReportAction(action))) {
return reportActions;
Copy link
Contributor

@ahmedGaber93 ahmedGaber93 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more context about this change? Also, reportActions are not sorted which make last message in pay report in LHN is not correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we well return all report action of the expense report which have already been sorted in the report screen.

Copy link
Contributor

@ahmedGaber93 ahmedGaber93 Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does reportActions.some((action) => isSentMoneyReportAction(action)) mean? Is this mean this a pay report? If that, can this condition return true on any other reports

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we need to fix this

reportActions are not sorted which make last message in pay report in LHN is not correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this only return true when we open the report preview of send money request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be more clean if we define it in a const and add some coments why we return reportActions in SentMoneyReport

const isSentMoneyReport = reportActions.some((action) => isSentMoneyReportAction(action))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmedGaber93 I updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkdengineer We still need to fix this #43742 (comment)
Steps to reproduce

  1. set Priority mode to most recent
  2. pay someone
  3. open pay report
  4. send message
    the message you sent it in step 3 not visible in LHN as last message you sent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmedGaber93 I fixed this case.

}

// 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}`];
Expand All @@ -326,9 +326,9 @@ function getCombinedReportActions(reportActions: ReportAction[], transactionThre
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;
}
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 @@ -2902,7 +2902,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 @@ -6594,7 +6594,11 @@ function getAllAncestorReportActions(report: Report | null | undefined): Ancesto
const parentReport = getReport(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 @@ -6640,7 +6644,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
5 changes: 2 additions & 3 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,10 @@ function ReportActionItem({
if (
isIOUReport(action) &&
action.originalMessage &&
// For the pay flow, we only want to show MoneyRequestAction when sending money. When paying, we display a regular system message
// For the pay flow, we only want to show MoneyRequestAction when sending money and we're not in the combine report. Otherwise, we display a regular system message
(action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
action.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.TRACK ||
isSendingMoney)
action.originalMessage.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 = action.originalMessage.IOUReportID ? action.originalMessage.IOUReportID.toString() : '-1';
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItemParentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function ReportActionItemParentAction({
}: ReportActionItemParentActionProps) {
const styles = useThemeStyles();
const ancestorIDs = useRef(ReportUtils.getAllAncestorReportActionIDs(report));

const [allAncestors, setAllAncestors] = useState<ReportUtils.Ancestor[]>([]);
const {isOffline} = useNetwork();

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
Loading