Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: message previews always include sender name #57911

Merged
merged 2 commits into from
Mar 10, 2025
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
8 changes: 6 additions & 2 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,14 @@ function uniqFast(items: string[]): string[] {
* Get the last actor display name from last actor details.
*/
function getLastActorDisplayName(lastActorDetails: Partial<PersonalDetails> | null, hasMultipleParticipants: boolean) {
return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID
if (!hasMultipleParticipants || !lastActorDetails) {
return '';
}

return lastActorDetails.accountID !== currentUserAccountID
? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
lastActorDetails.firstName || formatPhoneNumber(getDisplayNameOrDefault(lastActorDetails))
: '';
: translateLocal('common.you');
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
filterSelfDMChat,
filterWorkspaceChats,
formatMemberForList,
getLastActorDisplayName,
getMemberInviteOptions,
getSearchOptions,
getShareDestinationOptions,
Expand Down Expand Up @@ -811,6 +812,11 @@ describe('OptionsListUtils', () => {
expect(results.personalDetails.at(3)?.text).toBe('Invisible Woman');
});

it('getLastActorDisplayName()', () => {
expect(getLastActorDisplayName(PERSONAL_DETAILS['2'], true)).toBe('You');
expect(getLastActorDisplayName(PERSONAL_DETAILS['3'], true)).toBe('Spider-Man');
});

it('formatMemberForList()', () => {
const formattedMembers = Object.values(PERSONAL_DETAILS).map((personalDetail) => formatMemberForList(personalDetail));

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ describe('SidebarUtils', () => {
});

// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
expect(result?.alternateText).toBe(`invited 1 user`);
expect(result?.alternateText).toBe(`You invited 1 user`);
});
});
});
Expand Down