From 4296af6505d3f565789417c432a2b94bbd90d4ba Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Thu, 8 May 2025 15:56:24 +0700
Subject: [PATCH 1/7] make getReportDetails pure

---
 src/libs/ReportUtils.ts                        | 11 +++++------
 src/pages/home/report/PureReportActionItem.tsx |  4 ++--
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 56b242bd3210..5e69b3c898b4 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -5773,18 +5773,17 @@ function getDeletedTransactionMessage(action: ReportAction) {
     return message;
 }
 
-function getReportDetails(reportID: string): {reportName: string; reportUrl: string} {
-    const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
+function getReportDetails(reportID: string, report?: Report): {reportName: string; reportUrl: string} {
     return {
         reportName: getReportName(report) ?? report?.reportName ?? '',
         reportUrl: `${environmentURL}/r/${reportID}`,
     };
 }
 
-function getMovedTransactionMessage(action: ReportAction) {
+function getMovedTransactionMessage(action: ReportAction, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const {reportName, reportUrl} = getReportDetails(toReportID);
+    const {reportName, reportUrl} = getReportDetails(toReportID, report);
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,
         reportName,
@@ -5792,10 +5791,10 @@ function getMovedTransactionMessage(action: ReportAction) {
     return message;
 }
 
-function getUnreportedTransactionMessage(action: ReportAction) {
+function getUnreportedTransactionMessage(action: ReportAction, report?: Report) {
     const unreportedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION>) ?? {};
     const {fromReportID} = unreportedTransactionOriginalMessage as OriginalMessageUnreportedTransaction;
-    const {reportName, reportUrl} = getReportDetails(fromReportID);
+    const {reportName, reportUrl} = getReportDetails(fromReportID, report);
     const message = translateLocal('iou.unreportedTransaction', {
         reportUrl,
         reportName,
diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx
index e4b2ee3f9967..148f555536b8 100644
--- a/src/pages/home/report/PureReportActionItem.tsx
+++ b/src/pages/home/report/PureReportActionItem.tsx
@@ -1023,13 +1023,13 @@ function PureReportActionItem({
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION) {
             children = (
                 <ReportActionItemBasicMessage message="">
-                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action)}</muted-text></comment>`} />
+                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action, report)}</muted-text></comment>`} />
                 </ReportActionItemBasicMessage>
             );
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION) {
             children = (
                 <ReportActionItemBasicMessage message="">
-                    <RenderHTML html={`<comment><muted-text>${getUnreportedTransactionMessage(action)}</muted-text></comment>`} />
+                    <RenderHTML html={`<comment><muted-text>${getUnreportedTransactionMessage(action, report)}</muted-text></comment>`} />
                 </ReportActionItemBasicMessage>
             );
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION) {

From f57121ba3dcd9875aabbf9e10d7bea402ebbd973 Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Fri, 6 Jun 2025 23:45:29 +0700
Subject: [PATCH 2/7] remove getReportDetails

---
 src/libs/ReportUtils.ts                        | 12 +++---------
 src/pages/home/report/PureReportActionItem.tsx |  2 +-
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 5e5f909c1f89..132dfbd0d15f 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -5782,17 +5782,11 @@ function getDeletedTransactionMessage(action: ReportAction) {
     return message;
 }
 
-function getReportDetails(reportID: string, report?: Report): {reportName: string; reportUrl: string} {
-    return {
-        reportName: getReportName(report) ?? report?.reportName ?? '',
-        reportUrl: `${environmentURL}/r/${reportID}`,
-    };
-}
-
-function getMovedTransactionMessage(action: ReportAction, report?: Report) {
+function getMovedTransactionMessage(action: ReportAction, report?: Report, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const {reportName, reportUrl} = getReportDetails(toReportID, report);
+    const reportName = getReportName(report, undefined, parentReportActionParam) ?? report?.reportName ?? '';
+    const reportUrl = `${environmentURL}/r/${toReportID}`;
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,
         reportName,
diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx
index a7231f2437d8..4946ac94fd1b 100644
--- a/src/pages/home/report/PureReportActionItem.tsx
+++ b/src/pages/home/report/PureReportActionItem.tsx
@@ -1053,7 +1053,7 @@ function PureReportActionItem({
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION) {
             children = (
                 <ReportActionItemBasicMessage message="">
-                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action, report)}</muted-text></comment>`} />
+                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action, report, parentReportAction)}</muted-text></comment>`} />
                 </ReportActionItemBasicMessage>
             );
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION) {

From d9ffc26012acfb13f89ad1f170372c87b68e9626 Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Fri, 6 Jun 2025 23:53:28 +0700
Subject: [PATCH 3/7] fix type error

---
 src/libs/ReportUtils.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 132dfbd0d15f..c0e3939f124a 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -5782,10 +5782,10 @@ function getDeletedTransactionMessage(action: ReportAction) {
     return message;
 }
 
-function getMovedTransactionMessage(action: ReportAction, report?: Report, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>) {
+function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<ReportAction>, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const reportName = getReportName(report, undefined, parentReportActionParam) ?? report?.reportName ?? '';
+    const reportName = getReportName(report, undefined, parentReportAction) ?? report?.reportName ?? '';
     const reportUrl = `${environmentURL}/r/${toReportID}`;
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,

From 27a6d670530b1bf49335e183b21267ceb74b3cdf Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Mon, 9 Jun 2025 23:28:28 +0700
Subject: [PATCH 4/7] fix errors

---
 src/libs/ReportUtils.ts                        | 3 ++-
 src/pages/home/report/PureReportActionItem.tsx | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index c0e3939f124a..d03b12a70779 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -243,6 +243,7 @@ import {
     isScanning,
     isScanRequest as isScanRequestTransactionUtils,
 } from './TransactionUtils';
+import type * as OnyxTypes from '@src/types/onyx';
 import {addTrailingForwardSlash} from './Url';
 import type {AvatarSource} from './UserUtils';
 import {generateAccountID, getDefaultAvatarURL} from './UserUtils';
@@ -5782,7 +5783,7 @@ function getDeletedTransactionMessage(action: ReportAction) {
     return message;
 }
 
-function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<ReportAction>, report?: Report) {
+function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
     const reportName = getReportName(report, undefined, parentReportAction) ?? report?.reportName ?? '';
diff --git a/src/pages/home/report/PureReportActionItem.tsx b/src/pages/home/report/PureReportActionItem.tsx
index 4946ac94fd1b..1e05c6502010 100644
--- a/src/pages/home/report/PureReportActionItem.tsx
+++ b/src/pages/home/report/PureReportActionItem.tsx
@@ -1053,7 +1053,7 @@ function PureReportActionItem({
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION) {
             children = (
                 <ReportActionItemBasicMessage message="">
-                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action, report, parentReportAction)}</muted-text></comment>`} />
+                    <RenderHTML html={`<comment><muted-text>${getMovedTransactionMessage(action, parentReportAction, report)}</muted-text></comment>`} />
                 </ReportActionItemBasicMessage>
             );
         } else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION) {

From eb36352db4c34c03a164eaec2b87cc50ef73a696 Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Thu, 12 Jun 2025 01:00:26 +0700
Subject: [PATCH 5/7] apply suggestion

---
 src/libs/ReportUtils.ts | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index d03b12a70779..def8186b5e57 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -49,6 +49,7 @@ import type {
     TransactionViolation,
     UserWallet,
 } from '@src/types/onyx';
+import type * as OnyxTypes from '@src/types/onyx';
 import type {Attendee, Participant} from '@src/types/onyx/IOU';
 import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft';
 import type {OriginalMessageExportedToIntegration} from '@src/types/onyx/OldDotAction';
@@ -243,7 +244,6 @@ import {
     isScanning,
     isScanRequest as isScanRequestTransactionUtils,
 } from './TransactionUtils';
-import type * as OnyxTypes from '@src/types/onyx';
 import {addTrailingForwardSlash} from './Url';
 import type {AvatarSource} from './UserUtils';
 import {generateAccountID, getDefaultAvatarURL} from './UserUtils';
@@ -4701,7 +4701,7 @@ function getReportName(
     if (canUseDerivedValue && derivedNameExists) {
         return attributes[report.reportID].reportName;
     }
-    return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy});
+    return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy}) ?? report?.reportName ?? '';
 }
 
 function getSearchReportName(props: GetReportNameParams): string {
@@ -5783,11 +5783,15 @@ function getDeletedTransactionMessage(action: ReportAction) {
     return message;
 }
 
+function getReportUrl(reportID: string) {
+    return `${environmentURL}/r/${toReportID}`;
+}
+
 function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const reportName = getReportName(report, undefined, parentReportAction) ?? report?.reportName ?? '';
-    const reportUrl = `${environmentURL}/r/${toReportID}`;
+    const reportName = getReportName(report, undefined, parentReportAction);
+    const reportUrl = getReportUrl(toReportID);
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,
         reportName,

From d107aa41929f0d6f355055911a8c1fafd195c768 Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Thu, 12 Jun 2025 01:06:03 +0700
Subject: [PATCH 6/7] modify

---
 src/libs/ReportUtils.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index def8186b5e57..5848807fdbf2 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4701,7 +4701,7 @@ function getReportName(
     if (canUseDerivedValue && derivedNameExists) {
         return attributes[report.reportID].reportName;
     }
-    return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy}) ?? report?.reportName ?? '';
+    return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy});
 }
 
 function getSearchReportName(props: GetReportNameParams): string {
@@ -5784,13 +5784,13 @@ function getDeletedTransactionMessage(action: ReportAction) {
 }
 
 function getReportUrl(reportID: string) {
-    return `${environmentURL}/r/${toReportID}`;
+    return `${environmentURL}/r/${reportID}`;
 }
 
 function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const reportName = getReportName(report, undefined, parentReportAction);
+    const reportName = getReportName(report, undefined, parentReportAction) ?? report?.reportName ?? '';
     const reportUrl = getReportUrl(toReportID);
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,

From 7416613b75d95182acef41d39715ff20049fb998 Mon Sep 17 00:00:00 2001
From: cretadn22 <cretadn22@gmail.com>
Date: Thu, 12 Jun 2025 01:16:41 +0700
Subject: [PATCH 7/7] apply suggestion

---
 src/libs/ReportUtils.ts | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 5848807fdbf2..e7600386945a 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -49,7 +49,6 @@ import type {
     TransactionViolation,
     UserWallet,
 } from '@src/types/onyx';
-import type * as OnyxTypes from '@src/types/onyx';
 import type {Attendee, Participant} from '@src/types/onyx/IOU';
 import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft';
 import type {OriginalMessageExportedToIntegration} from '@src/types/onyx/OldDotAction';
@@ -4862,15 +4861,15 @@ function getReportNameInternal({
             if (isArchivedNonExpenseReport(report, getReportNameValuePairs(report?.reportID, reportNameValuePairs))) {
                 formattedName += ` (${translateLocal('common.archived')})`;
             }
-            return formatReportLastMessageText(formattedName);
+            return formatReportLastMessageText(formattedName) ?? report?.reportName ?? '';
         }
 
         if (!isEmptyObject(parentReportAction) && isOldDotReportAction(parentReportAction)) {
-            return getMessageOfOldDotReportAction(parentReportAction);
+            return getMessageOfOldDotReportAction(parentReportAction) ?? report?.reportName ?? '';
         }
 
         if (isRenamedAction(parentReportAction)) {
-            return getRenamedAction(parentReportAction, isExpenseReport(getReport(report.parentReportID, allReports)));
+            return getRenamedAction(parentReportAction, isExpenseReport(getReport(report.parentReportID, allReports))) ?? report?.reportName ?? '';
         }
 
         if (parentReportActionMessage?.isDeletedParentAction) {
@@ -4900,7 +4899,7 @@ function getReportNameInternal({
             return translateLocal('parentReportAction.hiddenMessage');
         }
         if (isAdminRoom(report) || isUserCreatedPolicyRoom(report)) {
-            return getAdminRoomInvitedParticipants(parentReportAction, reportActionMessage);
+            return getAdminRoomInvitedParticipants(parentReportAction, reportActionMessage) ?? report?.reportName ?? '';
         }
 
         // This will get removed as part of https://github.com/Expensify/App/issues/59961
@@ -4910,15 +4909,15 @@ function getReportNameInternal({
         }
         if (!isEmptyObject(parentReportAction) && isModifiedExpenseAction(parentReportAction)) {
             const modifiedMessage = ModifiedExpenseMessage.getForReportAction({reportOrID: report?.reportID, reportAction: parentReportAction, searchReports: reports});
-            return formatReportLastMessageText(modifiedMessage);
+            return formatReportLastMessageText(modifiedMessage) ?? report?.reportName ?? '';
         }
         if (isTripRoom(report) && report?.reportName !== CONST.REPORT.DEFAULT_REPORT_NAME) {
             return report?.reportName ?? '';
         }
         if (isCardIssuedAction(parentReportAction)) {
-            return getCardIssuedMessage({reportAction: parentReportAction});
+            return getCardIssuedMessage({reportAction: parentReportAction}) ?? report?.reportName ?? '';
         }
-        return reportActionMessage;
+        return reportActionMessage ?? report?.reportName ?? '';
     }
 
     if (isClosedExpenseReportWithNoExpenses(report, transactions)) {
@@ -4926,7 +4925,7 @@ function getReportNameInternal({
     }
 
     if (isGroupChat(report)) {
-        return getGroupChatName(undefined, true, report) ?? '';
+        return getGroupChatName(undefined, true, report) ?? report?.reportName ?? '';
     }
 
     if (isChatRoom(report)) {
@@ -4960,13 +4959,13 @@ function getReportNameInternal({
     }
 
     if (formattedName) {
-        return formatReportLastMessageText(formattedName);
+        return formatReportLastMessageText(formattedName) ?? report?.reportName ?? '';
     }
 
     // Not a room or PolicyExpenseChat, generate title from first 5 other participants
     formattedName = buildReportNameFromParticipantNames({report, personalDetails});
 
-    return formattedName;
+    return formattedName ?? report?.reportName ?? '';
 }
 
 /**
@@ -5787,10 +5786,10 @@ function getReportUrl(reportID: string) {
     return `${environmentURL}/r/${reportID}`;
 }
 
-function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>, report?: Report) {
+function getMovedTransactionMessage(action: ReportAction, parentReportAction: OnyxEntry<ReportAction>, report?: Report) {
     const movedTransactionOriginalMessage = getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION>) ?? {};
     const {toReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;
-    const reportName = getReportName(report, undefined, parentReportAction) ?? report?.reportName ?? '';
+    const reportName = getReportName(report, undefined, parentReportAction);
     const reportUrl = getReportUrl(toReportID);
     const message = translateLocal('iou.movedTransaction', {
         reportUrl,
