diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index cb8f1df50891..6c9b105e1d38 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -231,7 +231,7 @@ function createOption(logins, personalDetails, report, { let text; let alternateText; if (isChatRoom || isPolicyExpenseChat) { - text = (isArchivedRoom && report.isOwnPolicyExpenseChat) ? report.oldPolicyName : lodashGet(report, ['reportName'], ''); + text = lodashGet(report, ['reportName'], ''); alternateText = (showChatPreviewLine && !forcePolicyNamePreview && lastMessageText) ? lastMessageText : subtitle; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 5d9807854324..62b41231b58e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -141,17 +141,18 @@ function getParticipantEmailsFromReport({sharedReportList, reportNameValuePairs, * * @param {Object} fullReport * @param {String} chatType + * @param {String} oldPolicyName * @return {String} */ -function getChatReportName(fullReport, chatType) { +function getChatReportName(fullReport, chatType, oldPolicyName) { + const isArchivedRoom = ReportUtils.isArchivedRoom({ + chatType, + stateNum: fullReport.state, + statusNum: fullReport.status, + }); + if (ReportUtils.isDefaultRoom({chatType})) { - return `#${fullReport.reportName}${(ReportUtils.isArchivedRoom({ - chatType, - stateNum: fullReport.state, - statusNum: fullReport.status, - }) - ? ` (${Localize.translateLocal('common.deleted')})` - : '')}`; + return `#${fullReport.reportName}${isArchivedRoom ? ` (${Localize.translateLocal('common.deleted')})` : ''}`; } // For a basic policy room, return its original name @@ -160,13 +161,10 @@ function getChatReportName(fullReport, chatType) { } if (ReportUtils.isPolicyExpenseChat({chatType})) { - return `${LoginUtils.getEmailWithoutMergedAccountPrefix(fullReport.reportName)}${(ReportUtils.isArchivedRoom({ - chatType, - stateNum: fullReport.state, - statusNum: fullReport.status, - }) - ? ` (${Localize.translateLocal('common.archived')})` - : '')}`; + const name = (isArchivedRoom && fullReport.isOwnPolicyExpenseChat) + ? oldPolicyName + : LoginUtils.getEmailWithoutMergedAccountPrefix(lodashGet(fullReport, ['reportName'], '')); + return `${name}${isArchivedRoom ? ` (${Localize.translateLocal('common.archived')})` : ''}`; } const {sharedReportList} = fullReport; @@ -206,17 +204,17 @@ function getSimplifiedReportObject(report) { lastMessageText = ReportUtils.formatReportLastMessageText(lastMessageText); } + // Used for archived rooms, will store the policy name that the room used to belong to. + const oldPolicyName = lodashGet(report, ['reportNameValuePairs', 'oldPolicyName'], ''); + const reportName = lodashGet(report, ['reportNameValuePairs', 'type']) === 'chat' - ? getChatReportName(report, chatType) + ? getChatReportName(report, chatType, oldPolicyName) : report.reportName; const lastActorEmail = lodashGet(report, 'lastActionActorEmail', ''); const notificationPreference = ReportUtils.isChatRoom({chatType}) ? lodashGet(report, ['reportNameValuePairs', 'notificationPreferences', currentUserAccountID], 'daily') : ''; - // Used for archived rooms, will store the policy name that the room used to belong to. - const oldPolicyName = lodashGet(report, ['reportNameValuePairs', 'oldPolicyName'], ''); - // Used for User Created Policy Rooms, will denote how access to a chat room is given among workspace members const visibility = lodashGet(report, ['reportNameValuePairs', 'visibility']);