From 45ae762736a3852341eb06275508b41a1fe6c750 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Tue, 17 Sep 2024 03:08:25 -0400
Subject: [PATCH 01/13] fix lint

---
 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 a92c89479c74..c75d6a8e1dd4 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -1536,8 +1536,8 @@ function isChildReport(report: OnyxEntry<Report>): boolean {
  * the parentReportAction is a transaction.
  */
 function isExpenseRequest(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report)) {
-        const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+        const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
         return isExpenseReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction);
     }
@@ -1549,8 +1549,8 @@ function isExpenseRequest(report: OnyxInputOrEntry<Report>): boolean {
  * the parentReportAction is a transaction.
  */
 function isIOURequest(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report)) {
-        const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+        const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
         return isIOUReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction);
     }

From bfaa8d6aef7ff446b34f6bc5e2b76fa99731e413 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Tue, 17 Sep 2024 03:14:57 -0400
Subject: [PATCH 02/13] more lint changes

---
 src/libs/ReportUtils.ts | 21 ++++++++++++---------
 src/libs/actions/IOU.ts |  4 +++-
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index c75d6a8e1dd4..a8e6bd02a8cf 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -1562,8 +1562,8 @@ function isIOURequest(report: OnyxInputOrEntry<Report>): boolean {
  * parentReportAction has type of track.
  */
 function isTrackExpenseReport(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report)) {
-        const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+        const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         return !isEmptyObject(parentReportAction) && ReportActionsUtils.isTrackExpenseAction(parentReportAction);
     }
     return false;
@@ -2211,8 +2211,8 @@ function getIcons(
         };
         return [fallbackIcon];
     }
-    if (isExpenseRequest(report)) {
-        const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    if (isExpenseRequest(report) && report?.parentReportID && report.parentReportActionID) {
+        const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const workspaceIcon = getWorkspaceIcon(report, policy);
         const memberIcon = {
             source: personalDetails?.[parentReportAction?.actorAccountID ?? -1]?.avatar ?? FallbackAvatar,
@@ -2224,8 +2224,8 @@ function getIcons(
 
         return [memberIcon, workspaceIcon];
     }
-    if (isChatThread(report)) {
-        const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    if (isChatThread(report) && report?.parentReportID && report.parentReportActionID) {
+        const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
 
         const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
         const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false);
@@ -3106,7 +3106,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
     const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0;
     const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
 
-    const parentReportAction = ReportActionsUtils.getParentReportAction(moneyRequestReport);
+    const parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
 
     const isRequestIOU = isIOUReport(moneyRequestReport);
     const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID ?? '-1');
@@ -3713,7 +3713,10 @@ function getReportName(
     }
 
     let formattedName: string | undefined;
-    const parentReportAction = parentReportActionParam ?? ReportActionsUtils.getParentReportAction(report);
+    let parentReportAction: OnyxEntry<ReportAction> | undefined;
+    if (parentReportActionParam) {
+        parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+    }
     const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction);
 
     if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
@@ -5995,7 +5998,7 @@ function shouldReportBeInOptionList({
     // This can also happen for anyone accessing a public room or archived room for which they don't have access to the underlying policy.
     // Optionally exclude reports that do not belong to currently active workspace
 
-    const parentReportAction = ReportActionsUtils.getParentReportAction(report);
+    const parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
 
     if (
         !report?.reportID ||
diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index b0d025e0768f..4620be236a9f 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -2046,7 +2046,9 @@ function getMoneyRequestInformation(
     // STEP 2: Get the Expense/IOU report. If the moneyRequestReportID has been provided, we want to add the transaction to this specific report.
     // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
     let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
-    if (moneyRequestReportID) {
+    if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO) {
+        iouReport = null;
+    } else if (moneyRequestReportID) {
         iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
     } else {
         iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;

From a98a93f6b0e733eca5a838b1055c1785c28ddf13 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Tue, 17 Sep 2024 03:19:23 -0400
Subject: [PATCH 03/13] remove uneeded

---
 src/libs/actions/IOU.ts | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts
index 4620be236a9f..b0d025e0768f 100644
--- a/src/libs/actions/IOU.ts
+++ b/src/libs/actions/IOU.ts
@@ -2046,9 +2046,7 @@ function getMoneyRequestInformation(
     // STEP 2: Get the Expense/IOU report. If the moneyRequestReportID has been provided, we want to add the transaction to this specific report.
     // If no such reportID has been provided, let's use the chatReport.iouReportID property. In case that is not present, build a new optimistic Expense/IOU report.
     let iouReport: OnyxInputValue<OnyxTypes.Report> = null;
-    if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NO) {
-        iouReport = null;
-    } else if (moneyRequestReportID) {
+    if (moneyRequestReportID) {
         iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReportID}`] ?? null;
     } else {
         iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReport.iouReportID}`] ?? null;

From 0f674a1a229528f687bd7caa3945b7192d28ebf0 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Tue, 17 Sep 2024 03:21:44 -0400
Subject: [PATCH 04/13] prettier

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

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index a8e6bd02a8cf..eb86e53ff21e 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -3106,7 +3106,10 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
     const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0;
     const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
 
-    const parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+    const parentReportAction =
+        report?.parentReportID && report.parentReportActionID
+            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
+            : undefined;
 
     const isRequestIOU = isIOUReport(moneyRequestReport);
     const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID ?? '-1');
@@ -3715,7 +3718,10 @@ function getReportName(
     let formattedName: string | undefined;
     let parentReportAction: OnyxEntry<ReportAction> | undefined;
     if (parentReportActionParam) {
-        parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+        parentReportAction =
+            report?.parentReportID && report.parentReportActionID
+                ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
+                : undefined;
     }
     const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction);
 
@@ -5998,7 +6004,10 @@ function shouldReportBeInOptionList({
     // This can also happen for anyone accessing a public room or archived room for which they don't have access to the underlying policy.
     // Optionally exclude reports that do not belong to currently active workspace
 
-    const parentReportAction = report?.parentReportID && report.parentReportActionID ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+    const parentReportAction =
+        report?.parentReportID && report.parentReportActionID
+            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
+            : undefined;
 
     if (
         !report?.reportID ||

From 05d474aa78f19a4244365ff05a08a4812b6f7ca3 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Tue, 17 Sep 2024 03:31:04 -0400
Subject: [PATCH 05/13] fix 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 eb86e53ff21e..f4ad6a00a896 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -3107,8 +3107,8 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
     const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
 
     const parentReportAction =
-        report?.parentReportID && report.parentReportActionID
-            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
+        moneyRequestReport?.parentReportID && moneyRequestReport.parentReportActionID
+            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`]?.[moneyRequestReport.parentReportActionID]
             : undefined;
 
     const isRequestIOU = isIOUReport(moneyRequestReport);

From 075745198479378a9cdff4988a1958f3867446ea Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Wed, 18 Sep 2024 01:16:45 -0400
Subject: [PATCH 06/13] use message instead of originalMessage

---
 src/libs/ReportUtils.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index f4ad6a00a896..734828a6cb75 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4258,7 +4258,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
-    reportAction.reportAction.originalMessage = {
+    reportAction.reportAction.message = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,
         whisperedTo: [],

From da9621298ec9a06f32fa41c4bbf1b6ce343c7af1 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Wed, 18 Sep 2024 01:20:45 -0400
Subject: [PATCH 07/13] revert

---
 src/libs/ReportUtils.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 9093ee977a1d..0a55973b5ce8 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4257,7 +4257,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
-    reportAction.reportAction.message = {
+    reportAction.reportAction.originalMessage = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,
         whisperedTo: [],

From 1b0cce928285c90ac79f382c2c86996b3eaa9115 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Wed, 18 Sep 2024 01:45:03 -0400
Subject: [PATCH 08/13] remove eslint for setting optimistic data

---
 src/libs/ReportUtils.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 0a55973b5ce8..d1cf4b70a120 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4257,6 +4257,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
+    // eslint-disable-next-line deprecation/deprecation
     reportAction.reportAction.originalMessage = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,

From 5e94320264c7bb0cb74ce123e51d3a412aed9bd1 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Wed, 18 Sep 2024 02:01:13 -0400
Subject: [PATCH 09/13] remove specific deprecation

---
 src/libs/ReportUtils.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index d1cf4b70a120..dc0b444850f4 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4257,7 +4257,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
-    // eslint-disable-next-line deprecation/deprecation
+    // eslint-disable-next-line
     reportAction.reportAction.originalMessage = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,

From 2c8485d835d60217d5be82922abdb28664eccc14 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Thu, 19 Sep 2024 17:07:49 -0400
Subject: [PATCH 10/13] use isThread for checks

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

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index dc0b444850f4..8b5c930e5314 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -491,6 +491,11 @@ type ParsingDetails = {
     policyID?: string;
 };
 
+type Thread = {
+    parentReportID: string;
+    parentReportActionID: string;
+} & Report;
+
 let currentUserEmail: string | undefined;
 let currentUserPrivateDomain: string | undefined;
 let currentUserAccountID: number | undefined;
@@ -1111,14 +1116,14 @@ function isWorkspaceTaskReport(report: OnyxEntry<Report>): boolean {
 /**
  * Returns true if report has a parent
  */
-function isThread(report: OnyxInputOrEntry<Report>): boolean {
+function isThread(report: OnyxInputOrEntry<Report>): report is Thread {
     return !!(report?.parentReportID && report?.parentReportActionID);
 }
 
 /**
  * Returns true if report is of type chat and has a parent and is therefore a Thread.
  */
-function isChatThread(report: OnyxInputOrEntry<Report>): boolean {
+function isChatThread(report: OnyxInputOrEntry<Report>): report is Thread {
     return isThread(report) && report?.type === CONST.REPORT.TYPE.CHAT;
 }
 
@@ -1535,7 +1540,7 @@ function isChildReport(report: OnyxEntry<Report>): boolean {
  * the parentReportAction is a transaction.
  */
 function isExpenseRequest(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+    if (isThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
         return isExpenseReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction);
@@ -1548,7 +1553,7 @@ function isExpenseRequest(report: OnyxInputOrEntry<Report>): boolean {
  * the parentReportAction is a transaction.
  */
 function isIOURequest(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+    if (isThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
         return isIOUReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction);
@@ -1561,7 +1566,7 @@ function isIOURequest(report: OnyxInputOrEntry<Report>): boolean {
  * parentReportAction has type of track.
  */
 function isTrackExpenseReport(report: OnyxInputOrEntry<Report>): boolean {
-    if (isThread(report) && report?.parentReportID && report.parentReportActionID) {
+    if (isThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         return !isEmptyObject(parentReportAction) && ReportActionsUtils.isTrackExpenseAction(parentReportAction);
     }
@@ -2210,7 +2215,7 @@ function getIcons(
         };
         return [fallbackIcon];
     }
-    if (isExpenseRequest(report) && report?.parentReportID && report.parentReportActionID) {
+    if (isExpenseRequest(report) && isThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const workspaceIcon = getWorkspaceIcon(report, policy);
         const memberIcon = {
@@ -2223,7 +2228,7 @@ function getIcons(
 
         return [memberIcon, workspaceIcon];
     }
-    if (isChatThread(report) && report?.parentReportID && report.parentReportActionID) {
+    if (isChatThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
 
         const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
@@ -3106,7 +3111,7 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
     const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
 
     const parentReportAction =
-        moneyRequestReport?.parentReportID && moneyRequestReport.parentReportActionID
+        isThread(moneyRequestReport)
             ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`]?.[moneyRequestReport.parentReportActionID]
             : undefined;
 
@@ -3718,7 +3723,7 @@ function getReportName(
     let parentReportAction: OnyxEntry<ReportAction> | undefined;
     if (parentReportActionParam) {
         parentReportAction =
-            report?.parentReportID && report.parentReportActionID
+            isThread(report)
                 ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
                 : undefined;
     }
@@ -6005,7 +6010,7 @@ function shouldReportBeInOptionList({
     // Optionally exclude reports that do not belong to currently active workspace
 
     const parentReportAction =
-        report?.parentReportID && report.parentReportActionID
+        isThread(report)
             ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
             : undefined;
 

From bbdc0766dd282b246cf359c01afbb064ed8a7c6f Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Thu, 19 Sep 2024 17:13:06 -0400
Subject: [PATCH 11/13] one more

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

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 8b5c930e5314..8d4a157f1468 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -1539,7 +1539,7 @@ function isChildReport(report: OnyxEntry<Report>): boolean {
  * An Expense Request is a thread where the parent report is an Expense Report and
  * the parentReportAction is a transaction.
  */
-function isExpenseRequest(report: OnyxInputOrEntry<Report>): boolean {
+function isExpenseRequest(report: OnyxInputOrEntry<Report>): report is Thread {
     if (isThread(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const parentReport = ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
@@ -2215,7 +2215,7 @@ function getIcons(
         };
         return [fallbackIcon];
     }
-    if (isExpenseRequest(report) && isThread(report)) {
+    if (isExpenseRequest(report)) {
         const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
         const workspaceIcon = getWorkspaceIcon(report, policy);
         const memberIcon = {
@@ -3110,10 +3110,9 @@ function canHoldUnholdReportAction(reportAction: OnyxInputOrEntry<ReportAction>)
     const transactionID = moneyRequestReport ? ReportActionsUtils.getOriginalMessage(reportAction)?.IOUTransactionID : 0;
     const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? ({} as Transaction);
 
-    const parentReportAction =
-        isThread(moneyRequestReport)
-            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`]?.[moneyRequestReport.parentReportActionID]
-            : undefined;
+    const parentReportAction = isThread(moneyRequestReport)
+        ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.parentReportID}`]?.[moneyRequestReport.parentReportActionID]
+        : undefined;
 
     const isRequestIOU = isIOUReport(moneyRequestReport);
     const isHoldActionCreator = isHoldCreator(transaction, reportAction.childReportID ?? '-1');
@@ -3720,13 +3719,8 @@ function getReportName(
     }
 
     let formattedName: string | undefined;
-    let parentReportAction: OnyxEntry<ReportAction> | undefined;
-    if (parentReportActionParam) {
-        parentReportAction =
-            isThread(report)
-                ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
-                : undefined;
-    }
+    const parentReportAction =
+        parentReportActionParam && isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
     const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction);
 
     if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
@@ -6009,10 +6003,7 @@ function shouldReportBeInOptionList({
     // This can also happen for anyone accessing a public room or archived room for which they don't have access to the underlying policy.
     // Optionally exclude reports that do not belong to currently active workspace
 
-    const parentReportAction =
-        isThread(report)
-            ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID]
-            : undefined;
+    const parentReportAction = isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
 
     if (
         !report?.reportID ||

From 3bf7935824f1afec39ef745603bc7b82f0693903 Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Thu, 19 Sep 2024 17:27:00 -0400
Subject: [PATCH 12/13] null and specific error

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

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 8d4a157f1468..e873981663ec 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -3719,8 +3719,12 @@ function getReportName(
     }
 
     let formattedName: string | undefined;
-    const parentReportAction =
-        parentReportActionParam && isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+    let parentReportAction: OnyxEntry<ReportAction>;
+    if (parentReportActionParam) {
+        parentReportAction = parentReportActionParam;
+    } else {
+        parentReportAction = isThread(report) ? allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID] : undefined;
+    }
     const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction);
 
     if (parentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.SUBMITTED) {
@@ -4256,7 +4260,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
-    // eslint-disable-next-line
+    // eslint-disable-next-line deprecation/deprecation
     reportAction.reportAction.originalMessage = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,

From d79094031ec42f2a3a6ef903ca6301110a0e4e3f Mon Sep 17 00:00:00 2001
From: Srikar Parsi <srikar.parsi@expensify.com>
Date: Thu, 19 Sep 2024 18:08:21 -0400
Subject: [PATCH 13/13] dont specify error

---
 src/libs/ReportUtils.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index e873981663ec..7d2cc4a27130 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -4260,7 +4260,7 @@ function buildOptimisticTaskCommentReportAction(
 
     // These parameters are not saved on the reportAction, but are used to display the task in the UI
     // Added when we fetch the reportActions on a report
-    // eslint-disable-next-line deprecation/deprecation
+    // eslint-disable-next-line
     reportAction.reportAction.originalMessage = {
         html: ReportActionsUtils.getReportActionHtml(reportAction.reportAction),
         taskReportID: ReportActionsUtils.getReportActionMessage(reportAction.reportAction)?.taskReportID,
