From ef85f95ffec2bef8200a84a0933e25faffe5937e Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 6 Mar 2025 11:08:27 +0700 Subject: [PATCH 1/2] fix: message previews always include sender name --- src/libs/OptionsListUtils.ts | 8 ++++++-- tests/unit/OptionsListUtilsTest.ts | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 4910254d5cfc0..b42bbc1335689 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -534,10 +534,14 @@ function uniqFast(items: string[]): string[] { * Get the last actor display name from last actor details. */ function getLastActorDisplayName(lastActorDetails: Partial | 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'); } /** diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index 5a964cd7d6f04..417eba2938695 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -13,6 +13,7 @@ import { filterSelfDMChat, filterWorkspaceChats, formatMemberForList, + getLastActorDisplayName, getMemberInviteOptions, getSearchOptions, getShareDestinationOptions, @@ -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)); From 6169cfdc76156190d254ba0ec7f8ffaea1b420b0 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Thu, 6 Mar 2025 15:09:55 +0700 Subject: [PATCH 2/2] fix lint --- tests/unit/SidebarUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index d3c0d6d7ee615..2771a2c5f78e4 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -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`); }); }); });