From 2aa4e8ff48d65d707489d8c14c776f977abeee20 Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Thu, 27 Mar 2025 20:03:22 +0300 Subject: [PATCH 1/6] fix: no preview message after switching priorities Signed-off-by: Mustafa Daglioglu --- src/libs/OptionsListUtils.ts | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9f5b061cba41..e99d07e9fd93 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -551,6 +551,20 @@ function getLastActorDisplayName(lastActorDetails: Partial | nu : translateLocal('common.you'); } +/** + * Get the last actor last name from last actor details. + */ +function getLastActorLastName(lastActorDetails: Partial | null) { + if (!lastActorDetails) { + return ''; + } + + return lastActorDetails.accountID !== currentUserAccountID + ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + lastActorDetails.lastName || '' + : ''; +} + /** * Update alternate text for the option when applicable */ @@ -702,7 +716,30 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails true, lastReportAction, ); + lastMessageTextFromReport = formatReportLastMessageText(reportPreviewMessage); + + // If lastMessageTextFromReport is empty, try to extract the message from the lastReportAction instead + if (!lastMessageTextFromReport) { + const lastReportActionMessage = getReportActionMessageText(lastReportAction); + lastMessageTextFromReport = lastReportActionMessage; + + // Get the actor's display name instead of using email + const actorAccountID = lastReportAction?.actorAccountID; + const actorDetails = actorAccountID ? allPersonalDetails?.[actorAccountID] : null; + + if (actorDetails) { + const actorDisplayName = getLastActorDisplayName(actorDetails); + const actorLastName = getLastActorLastName(actorDetails); + + const actorName = actorLastName ? `${actorDisplayName} ${actorLastName}` : actorDisplayName; + + // Format the message with the display name if available + if (actorDisplayName && actorDetails.login) { + lastMessageTextFromReport = lastMessageTextFromReport.replace(actorDetails.login, actorName); + } + } + } } else if (isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = getReimbursementQueuedActionMessage({reportAction: lastReportAction, reportOrID: report}); } else if (isReimbursementDeQueuedAction(lastReportAction)) { From ec8a498d0870fae8cd9d19fef89ed1353a387bdb Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Tue, 1 Apr 2025 12:43:36 +0300 Subject: [PATCH 2/6] fix(OptionsListUtils): use lastReportAction as fallback for lastIOUMoneyReportAction Ensure the report preview message is correctly formatted by using lastReportAction as a fallback when lastIOUMoneyReportAction is null. This prevents empty message texts and improves the display of actor details. Signed-off-by: Mustafa Daglioglu --- src/libs/OptionsListUtils.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index e99d07e9fd93..6a7f5542aa54 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -709,7 +709,7 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails : undefined; const reportPreviewMessage = getReportPreviewMessage( !isEmptyObject(iouReport) ? iouReport : null, - lastIOUMoneyReportAction, + lastIOUMoneyReportAction ?? lastReportAction, true, reportUtilsIsChatReport(report), null, @@ -719,11 +719,8 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails lastMessageTextFromReport = formatReportLastMessageText(reportPreviewMessage); - // If lastMessageTextFromReport is empty, try to extract the message from the lastReportAction instead - if (!lastMessageTextFromReport) { - const lastReportActionMessage = getReportActionMessageText(lastReportAction); - lastMessageTextFromReport = lastReportActionMessage; - + // If lastIOUMoneyReportAction is empty, format the message with the actor's display name + if (!lastIOUMoneyReportAction) { // Get the actor's display name instead of using email const actorAccountID = lastReportAction?.actorAccountID; const actorDetails = actorAccountID ? allPersonalDetails?.[actorAccountID] : null; From 845a44f6a38f0d926728c49c4838004a751c6378 Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Fri, 4 Apr 2025 13:12:24 +0300 Subject: [PATCH 3/6] remove redundant checks and formatting last message Signed-off-by: Mustafa Daglioglu --- src/libs/OptionsListUtils.ts | 19 ------------------- src/libs/ReportUtils.ts | 11 +++-------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 6a7f5542aa54..868199d96198 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -718,25 +718,6 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails ); lastMessageTextFromReport = formatReportLastMessageText(reportPreviewMessage); - - // If lastIOUMoneyReportAction is empty, format the message with the actor's display name - if (!lastIOUMoneyReportAction) { - // Get the actor's display name instead of using email - const actorAccountID = lastReportAction?.actorAccountID; - const actorDetails = actorAccountID ? allPersonalDetails?.[actorAccountID] : null; - - if (actorDetails) { - const actorDisplayName = getLastActorDisplayName(actorDetails); - const actorLastName = getLastActorLastName(actorDetails); - - const actorName = actorLastName ? `${actorDisplayName} ${actorLastName}` : actorDisplayName; - - // Format the message with the display name if available - if (actorDisplayName && actorDetails.login) { - lastMessageTextFromReport = lastMessageTextFromReport.replace(actorDetails.login, actorName); - } - } - } } else if (isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = getReimbursementQueuedActionMessage({reportAction: lastReportAction, reportOrID: report}); } else if (isReimbursementDeQueuedAction(lastReportAction)) { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8d421fca3ea9..67b05ce3cc8c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4014,7 +4014,9 @@ function getReportPreviewMessage( const report = typeof reportOrID === 'string' ? getReport(reportOrID, allReports) : reportOrID; const reportActionMessage = getReportActionHtml(iouReportAction); - if (!report?.reportID) { + if (isEmptyObject(report) || !report?.reportID) { + // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled + // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE return reportActionMessage; } @@ -4022,12 +4024,6 @@ function getReportPreviewMessage( const transactionsWithReceipts = allReportTransactions.filter(hasReceiptTransactionUtils); const numberOfScanningReceipts = transactionsWithReceipts.filter(isReceiptBeingScanned).length; - if (isEmptyObject(report) || !report?.reportID) { - // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled - // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE - return reportActionMessage; - } - if (!isEmptyObject(iouReportAction) && !isIOUReport(report) && iouReportAction && isSplitBillReportAction(iouReportAction)) { // This covers group chats where the last action is a split expense action const linkedTransaction = getLinkedTransaction(iouReportAction); @@ -4153,7 +4149,6 @@ function getReportPreviewMessage( // if we have the amount in the originalMessage and lastActorID, we can use that to display the preview message for the latest expense if (amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) { const amountToDisplay = convertToDisplayString(Math.abs(amount), currency); - // We only want to show the actor name in the preview if it's not the current user who took the action const requestorName = lastActorID && lastActorID !== currentUserAccountID ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport}) : ''; From 7e158d4a6f91e42778c2268db3d78c8f5adae03e Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Fri, 4 Apr 2025 13:15:42 +0300 Subject: [PATCH 4/6] revert unnecessary changes Signed-off-by: Mustafa Daglioglu --- src/libs/OptionsListUtils.ts | 15 --------------- src/libs/ReportUtils.ts | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 868199d96198..22382a4bff39 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -551,20 +551,6 @@ function getLastActorDisplayName(lastActorDetails: Partial | nu : translateLocal('common.you'); } -/** - * Get the last actor last name from last actor details. - */ -function getLastActorLastName(lastActorDetails: Partial | null) { - if (!lastActorDetails) { - return ''; - } - - return lastActorDetails.accountID !== currentUserAccountID - ? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - lastActorDetails.lastName || '' - : ''; -} - /** * Update alternate text for the option when applicable */ @@ -716,7 +702,6 @@ function getLastMessageTextForReport(report: OnyxEntry, lastActorDetails true, lastReportAction, ); - lastMessageTextFromReport = formatReportLastMessageText(reportPreviewMessage); } else if (isReimbursementQueuedAction(lastReportAction)) { lastMessageTextFromReport = getReimbursementQueuedActionMessage({reportAction: lastReportAction, reportOrID: report}); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 67b05ce3cc8c..65967b6bfed1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4149,6 +4149,7 @@ function getReportPreviewMessage( // if we have the amount in the originalMessage and lastActorID, we can use that to display the preview message for the latest expense if (amount !== undefined && lastActorID && !isPreviewMessageForParentChatReport) { const amountToDisplay = convertToDisplayString(Math.abs(amount), currency); + // We only want to show the actor name in the preview if it's not the current user who took the action const requestorName = lastActorID && lastActorID !== currentUserAccountID ? getDisplayNameForParticipant({accountID: lastActorID, shouldUseShortForm: !isPreviewMessageForParentChatReport}) : ''; From 5bdc75c675c0bdbd635c7481feb90aefc436d3b3 Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Fri, 4 Apr 2025 14:10:44 +0300 Subject: [PATCH 5/6] clarify comment about missing IOU report details Signed-off-by: Mustafa Daglioglu --- src/libs/ReportUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 65967b6bfed1..0322f831b20a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4015,7 +4015,9 @@ function getReportPreviewMessage( const reportActionMessage = getReportActionHtml(iouReportAction); if (isEmptyObject(report) || !report?.reportID) { - // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled + // The IOU report associated with this action might not be loaded into the 'allReports' + // Alternatively, settled IOU reports might not be returned by the backend's OpenApp command. + // In either case, we lack the full report details needed for rich formatting, // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE return reportActionMessage; } From 10c3dfbc50a8b0419071fce31ee7174b8d8f13d9 Mon Sep 17 00:00:00 2001 From: Mustafa Daglioglu Date: Fri, 4 Apr 2025 18:45:40 +0300 Subject: [PATCH 6/6] clarify comment for unavailable iouReport Signed-off-by: Mustafa Daglioglu --- src/libs/ReportUtils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0322f831b20a..fd365510109d 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4015,10 +4015,10 @@ function getReportPreviewMessage( const reportActionMessage = getReportActionHtml(iouReportAction); if (isEmptyObject(report) || !report?.reportID) { - // The IOU report associated with this action might not be loaded into the 'allReports' - // Alternatively, settled IOU reports might not be returned by the backend's OpenApp command. - // In either case, we lack the full report details needed for rich formatting, - // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE + // This iouReport may be unavailable for one of the following reasons: + // 1. After SignIn, the OpenApp API won't return iouReports if they're settled. + // 2. The iouReport exists in local storage but hasn't been loaded into the allReports. It will be loaded automatically when the user opens the iouReport. + // Until we know how to solve this the best, we just display the report action message. return reportActionMessage; }