Skip to content

Commit e091fc2

Browse files
authored
Merge pull request #57911 from nkdengineer/fix/57038-fu
fix: message previews always include sender name
2 parents 1ba7a1d + 6169cfd commit e091fc2

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/libs/OptionsListUtils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,14 @@ function uniqFast(items: string[]): string[] {
534534
* Get the last actor display name from last actor details.
535535
*/
536536
function getLastActorDisplayName(lastActorDetails: Partial<PersonalDetails> | null, hasMultipleParticipants: boolean) {
537-
return hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID
537+
if (!hasMultipleParticipants || !lastActorDetails) {
538+
return '';
539+
}
540+
541+
return lastActorDetails.accountID !== currentUserAccountID
538542
? // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
539543
lastActorDetails.firstName || formatPhoneNumber(getDisplayNameOrDefault(lastActorDetails))
540-
: '';
544+
: translateLocal('common.you');
541545
}
542546

543547
/**

tests/unit/OptionsListUtilsTest.ts

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
filterSelfDMChat,
1414
filterWorkspaceChats,
1515
formatMemberForList,
16+
getLastActorDisplayName,
1617
getMemberInviteOptions,
1718
getSearchOptions,
1819
getShareDestinationOptions,
@@ -828,6 +829,11 @@ describe('OptionsListUtils', () => {
828829
expect(results.personalDetails.at(3)?.text).toBe('Invisible Woman');
829830
});
830831

832+
it('getLastActorDisplayName()', () => {
833+
expect(getLastActorDisplayName(PERSONAL_DETAILS['2'], true)).toBe('You');
834+
expect(getLastActorDisplayName(PERSONAL_DETAILS['3'], true)).toBe('Spider-Man');
835+
});
836+
831837
it('formatMemberForList()', () => {
832838
const formattedMembers = Object.values(PERSONAL_DETAILS).map((personalDetail) => formatMemberForList(personalDetail));
833839

tests/unit/SidebarUtilsTest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ describe('SidebarUtils', () => {
633633
});
634634

635635
// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
636-
expect(result?.alternateText).toBe(`invited 1 user`);
636+
expect(result?.alternateText).toBe(`You invited 1 user`);
637637
});
638638
});
639639
});

0 commit comments

Comments
 (0)