From 8e1d451290cf853e06f64997fc62e1f393e2aaaa Mon Sep 17 00:00:00 2001 From: Pavlo Tsimura Date: Thu, 11 Jan 2024 18:03:35 +0100 Subject: [PATCH] Use report.lastMessageText as the all-case fallback --- src/libs/OptionsListUtils.js | 7 +++---- src/libs/PersonalDetailsUtils.ts | 32 -------------------------------- src/libs/SidebarUtils.ts | 2 +- 3 files changed, 4 insertions(+), 37 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f86ac5457c49..0be73ce2735e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -397,10 +397,9 @@ function getAllReportErrors(report, reportActions) { /** * Get the last message text from the report directly or from other sources for special cases. * @param {Object} report - * @param {Object[]} personalDetails - list of personal details of the report participants * @returns {String} */ -function getLastMessageTextForReport(report, personalDetails) { +function getLastMessageTextForReport(report) { const lastReportAction = _.find(allSortedReportActions[report.reportID], (reportAction) => ReportActionUtils.shouldReportActionBeVisibleAsLastAction(reportAction)); let lastMessageTextFromReport = ''; const lastActionName = lodashGet(lastReportAction, 'actionName', ''); @@ -439,7 +438,7 @@ function getLastMessageTextForReport(report, personalDetails) { lastMessageTextFromReport = TaskUtils.getTaskCreatedMessage(lastReportAction); } - return lastMessageTextFromReport || PersonalDetailsUtils.replaceLoginsWithDisplayNames(lodashGet(report, 'lastMessageText', ''), personalDetails); + return lastMessageTextFromReport || lodashGet(report, 'lastMessageText', ''); } /** @@ -527,7 +526,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat; subtitle = ReportUtils.getChatRoomSubtitle(report); - const lastMessageTextFromReport = getLastMessageTextForReport(report, personalDetailList); + const lastMessageTextFromReport = getLastMessageTextForReport(report); const lastActorDetails = personalDetailMap[report.lastActorAccountID] || null; const lastActorDisplayName = hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts index 5a2f525dec43..3346094adeec 100644 --- a/src/libs/PersonalDetailsUtils.ts +++ b/src/libs/PersonalDetailsUtils.ts @@ -7,28 +7,13 @@ import * as LocalePhoneNumber from './LocalePhoneNumber'; import * as Localize from './Localize'; import * as UserUtils from './UserUtils'; -let sessionUserAccountID: number | undefined; -Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (value) => { - // When signed out, val is undefined - if (!value) { - return; - } - - sessionUserAccountID = value.accountID; - }, -}); - let personalDetails: Array = []; let allPersonalDetails: OnyxEntry = {}; -let currentUserPersonalDetails: OnyxEntry; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, callback: (val) => { personalDetails = Object.values(val ?? {}); allPersonalDetails = val; - currentUserPersonalDetails = val?.[sessionUserAccountID ?? -1] ?? null; }, }); @@ -38,22 +23,6 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial((replacedText, detail) => { - if (!detail.login) { - return replacedText; - } - - return replacedText.replaceAll(detail.login, getDisplayNameOrDefault(detail)); - }, text); - - if (!includeCurrentAccount || !currentUserPersonalDetails) { - return result; - } - - return result.replaceAll(currentUserPersonalDetails.login ?? '', getDisplayNameOrDefault(currentUserPersonalDetails)); -} - /** * Given a list of account IDs (as number) it will return an array of personal details objects. * @param accountIDs - Array of accountIDs @@ -239,5 +208,4 @@ export { getFormattedStreet, getStreetLines, getEffectiveDisplayName, - replaceLoginsWithDisplayNames, }; diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 8631c7ceeb12..6e46ec320066 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -323,7 +323,7 @@ function getOptionData( // We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade. const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants); - const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report, displayNamesWithTooltips); + const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(report); // If the last actor's details are not currently saved in Onyx Collection, // then try to get that from the last report action if that action is valid