diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 26afd195e9a13..88f138a1cc353 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9402,6 +9402,17 @@ function reasonForReportToBeInOptionList({ const isEmptyChat = isEmptyReport(report, isReportArchived); const canHideReport = shouldHideReport(report, currentReportId, isReportArchived); + // Drafts already return early above, so no draft check needed here + if (isChatThread(report) && isEmptyChat) { + const isParentDeleted = !isEmptyObject(parentReportAction) && isDeletedAction(parentReportAction); + const isParentPendingDelete = !isEmptyObject(parentReportAction) && parentReportAction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; + const hasReplies = (parentReportAction?.childVisibleActionCount ?? 0) > 0; + + if ((isParentDeleted || isParentPendingDelete) && !hasReplies) { + return null; + } + } + // Include reports if they are pinned if (report.isPinned) { return CONST.REPORT_IN_LHN_REASONS.PINNED_BY_USER; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 05d4935f0fe7f..d52f03d7acd4e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2044,7 +2044,7 @@ function deleteReportComment( } // If the API call fails we must show the original message again, so we revert the message content back to how it was // and and remove the pendingAction so the strike-through clears - const failureData: Array> = [ + const failureData: Array> = [ { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`, @@ -2090,6 +2090,30 @@ function deleteReportComment( optimisticData.push(...getOptimisticDataForAncestors(ancestors, optimisticReport?.lastVisibleActionCreated ?? '', CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)); } + // Force LHN re-evaluation for empty child thread by triggering an Onyx update + if (reportAction.childReportID && childVisibleActionCount === 0) { + const childReportKey: `${typeof ONYXKEYS.COLLECTION.REPORT}${string}` = `${ONYXKEYS.COLLECTION.REPORT}${reportAction.childReportID}`; + const childReport = allReports?.[childReportKey]; + + if (childReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: childReportKey, + value: { + lastMessageText: '', + }, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: childReportKey, + value: { + lastMessageText: childReport.lastMessageText ?? '', + }, + }); + } + } + const parameters: DeleteCommentParams = { reportID: originalReportID, reportActionID,