diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 35eb00229b72..31402a0fd740 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -494,9 +494,16 @@ function getOptions(reports, personalDetails, { reportMapForLogins[logins[0]] = report; } const isSearchingSomeonesPolicyExpenseChat = !report.isOwnPolicyExpenseChat && searchValue !== ''; + + // Checks to see if the current user is the admin of the policy, if so the policy + // name preview will be shown. + const isPolicyChatAdmin = ReportUtils.isPolicyExpenseChatAdmin(report, policies); + allReportOptions.push(createOption(logins, personalDetails, report, reportActions, { showChatPreviewLine, - forcePolicyNamePreview: isPolicyExpenseChat ? isSearchingSomeonesPolicyExpenseChat : forcePolicyNamePreview, + forcePolicyNamePreview: isPolicyExpenseChat + ? (isSearchingSomeonesPolicyExpenseChat || isPolicyChatAdmin) + : forcePolicyNamePreview, })); }); diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 752ceddd79f8..1b637537f2f5 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -318,6 +318,25 @@ function getPolicyName(report, policies) { || Localize.translateLocal('workspace.common.unavailable'); } +/** + * Checks if the current user is the admin of the policy given the policy expense chat. + * @param {Object} report + * @param {String} report.policyID + * @param {Object} policies must have OnyxKey prefix (i.e 'policy_') for keys + * @returns {Boolean} + */ +function isPolicyExpenseChatAdmin(report, policies) { + if (!isPolicyExpenseChat(report)) { + return false; + } + + const policyRole = lodashGet(policies, [ + `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role', + ]); + + return policyRole === CONST.POLICY.ROLE.ADMIN; +} + /** * Get either the policyName or domainName the chat is tied to * @param {Object} report @@ -1676,6 +1695,7 @@ export { getPolicyName, getPolicyType, isArchivedRoom, + isPolicyExpenseChatAdmin, isPublicRoom, isConciergeChatReport, hasAutomatedExpensifyEmails, diff --git a/src/libs/SidebarUtils.js b/src/libs/SidebarUtils.js index d333b194c355..99429caa7e04 100644 --- a/src/libs/SidebarUtils.js +++ b/src/libs/SidebarUtils.js @@ -275,7 +275,10 @@ function getOptionData(reportID) { } if (result.isChatRoom || result.isPolicyExpenseChat) { - result.alternateText = lastMessageText || Localize.translate(preferredLocale, 'report.noActivityYet'); + // Checks to see if the current user is the admin of the policy tied to the policy expense chat, + // if so the policy name preview will be shown. + const isPolicyChatAdmin = result.isPolicyExpenseChat && ReportUtils.isPolicyExpenseChatAdmin(report, policies); + result.alternateText = isPolicyChatAdmin ? subtitle : (lastMessageText || Localize.translate(preferredLocale, 'report.noActivityYet')); } else { if (!lastMessageText) { // Here we get the beginning of chat history message and append the display name for each user, adding pronouns if there are any.