Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
isArchivedReport,
isChatThread,
isDefaultRoom,
isDM,
isDraftReport,
isExpenseReport,
isHiddenForCurrentUser,
Expand Down Expand Up @@ -551,6 +552,23 @@ function getLastActorDisplayName(lastActorDetails: Partial<PersonalDetails> | nu
: translateLocal('common.you');
}

/**
* Should show the last actor display name from last actor details.
*/
function shouldShowLastActorDisplayName(report: OnyxEntry<Report>, lastActorDetails: Partial<PersonalDetails> | null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to return false when the actionName is IOU or REPORT_PREVIEW, which caused #59778

if (!lastActorDetails || reportUtilsIsSelfDM(report) || (isDM(report) && lastActorDetails.accountID !== currentUserAccountID)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentUserAccountID is not synced with the UI, so its value can be stale in some cases. For example, which caused the issue: #77443 (comment). We addressed it in this PR: #79669

return false;
}

const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);

if (!lastActorDisplayName) {
return false;
}

return true;
}

/**
* Update alternate text for the option when applicable
*/
Expand Down Expand Up @@ -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}`;
}
Expand Down Expand Up @@ -2314,6 +2335,7 @@ export {
getIsUserSubmittedExpenseOrScannedReceipt,
getManagerMcTestParticipant,
isSelectedManagerMcTest,
shouldShowLastActorDisplayName,
};

export type {Section, SectionBase, MemberForList, Options, OptionList, SearchOption, PayeePersonalDetails, Option, OptionTree, ReportAndPersonalDetailOptions, GetUserToInviteConfig};
13 changes: 5 additions & 8 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -89,7 +89,6 @@ import {
isChatThread,
isConciergeChatReport,
isDeprecatedGroupDM,
isDM,
isDomainRoom,
isExpenseReport,
isExpenseRequest,
Expand Down Expand Up @@ -517,7 +516,6 @@ function getOptionData({
}

const lastActorDisplayName = getLastActorDisplayName(lastActorDetails);

let lastMessageTextFromReport = lastMessageTextFromReportProp;
if (!lastMessageTextFromReport) {
lastMessageTextFromReport = getLastMessageTextForReport(report, lastActorDetails, policy);
Expand Down Expand Up @@ -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;
}
}

Expand Down