diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index d1f5ca29b7cf..daf2cf608a66 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -106,6 +106,7 @@ import { isArchivedReport, isChatThread, isDefaultRoom, + isDM, isDraftReport, isExpenseReport, isHiddenForCurrentUser, @@ -551,6 +552,23 @@ function getLastActorDisplayName(lastActorDetails: Partial | nu : translateLocal('common.you'); } +/** + * Should show the last actor display name from last actor details. + */ +function shouldShowLastActorDisplayName(report: OnyxEntry, lastActorDetails: Partial | null) { + if (!lastActorDetails || reportUtilsIsSelfDM(report) || (isDM(report) && lastActorDetails.accountID !== currentUserAccountID)) { + return false; + } + + const lastActorDisplayName = getLastActorDisplayName(lastActorDetails); + + if (!lastActorDisplayName) { + return false; + } + + return true; +} + /** * Update alternate text for the option when applicable */ @@ -868,8 +886,11 @@ function createOption( let lastMessageText = lastMessageTextFromReport; const lastAction = lastVisibleReportActions[report.reportID]; - const shouldDisplayLastActorName = lastAction && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU; - + const shouldDisplayLastActorName = + lastAction && + lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && + lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU && + shouldShowLastActorDisplayName(report, lastActorDetails); if (shouldDisplayLastActorName && lastActorDisplayName && lastMessageTextFromReport) { lastMessageText = `${lastActorDisplayName}: ${lastMessageTextFromReport}`; } @@ -2314,6 +2335,7 @@ export { getIsUserSubmittedExpenseOrScannedReceipt, getManagerMcTestParticipant, isSelectedManagerMcTest, + shouldShowLastActorDisplayName, }; export type {Section, SectionBase, MemberForList, Options, OptionList, SearchOption, PayeePersonalDetails, Option, OptionTree, ReportAndPersonalDetailOptions, GetUserToInviteConfig}; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 9e5e33ceaa15..bba8eda7d020 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -18,7 +18,7 @@ import {hasValidDraftComment} from './DraftCommentUtils'; import localeCompare from './LocaleCompare'; import {formatPhoneNumber} from './LocalePhoneNumber'; import {translate, translateLocal} from './Localize'; -import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs} from './OptionsListUtils'; +import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs, shouldShowLastActorDisplayName} from './OptionsListUtils'; import Parser from './Parser'; import Performance from './Performance'; import {getCleanedTagName, getPolicy} from './PolicyUtils'; @@ -89,7 +89,6 @@ import { isChatThread, isConciergeChatReport, isDeprecatedGroupDM, - isDM, isDomainRoom, isExpenseReport, isExpenseRequest, @@ -517,7 +516,6 @@ function getOptionData({ } const lastActorDisplayName = getLastActorDisplayName(lastActorDetails); - let lastMessageTextFromReport = lastMessageTextFromReportProp; if (!lastMessageTextFromReport) { lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, policy); @@ -646,12 +644,11 @@ function getOptionData({ if (!lastMessageText) { lastMessageText = formatReportLastMessageText(getWelcomeMessage(report, policy).messageText ?? translateLocal('report.noActivityYet')); } - if (isDM(report) && lastActorDisplayName !== translateLocal('common.you')) { - result.alternateText = formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin; + + if (shouldShowLastActorDisplayName(report, lastActorDetails)) { + result.alternateText = `${lastActorDisplayName}: ${formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin}`; } else { - result.alternateText = lastActorDisplayName - ? `${lastActorDisplayName}: ${formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin}` - : formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin; + result.alternateText = formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin; } }