Skip to content

Commit

Permalink
Use report.lastMessageText as the all-case fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
paultsimura committed Jan 11, 2024
1 parent 06da36a commit 8e1d451
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
7 changes: 3 additions & 4 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand Down Expand Up @@ -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', '');
}

/**
Expand Down Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PersonalDetails | null> = [];
let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
personalDetails = Object.values(val ?? {});
allPersonalDetails = val;
currentUserPersonalDetails = val?.[sessionUserAccountID ?? -1] ?? null;
},
});

Expand All @@ -38,22 +23,6 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial<PersonalDetails
return displayName || defaultValue || fallbackValue;
}

function replaceLoginsWithDisplayNames(text: string, details: PersonalDetails[], includeCurrentAccount = true): string {
const result = details.reduce<string>((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
Expand Down Expand Up @@ -239,5 +208,4 @@ export {
getFormattedStreet,
getStreetLines,
getEffectiveDisplayName,
replaceLoginsWithDisplayNames,
};
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e1d451

Please sign in to comment.