From 2588270466c1dfc22f72091741ed26d7a6bc5910 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:49:03 -0600 Subject: [PATCH] Use system nickname or first name for incoming group calls Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com> --- ts/components/CallingLobby.tsx | 9 ++++++- ts/components/CallingPreCallInfo.tsx | 14 +++++++++-- ts/components/IncomingCallBar.tsx | 24 +++++++++++++++---- .../util/callingGetParticipantName_test.ts | 21 ++++++++++++++++ ts/util/callingGetParticipantName.ts | 14 +++++++++-- 5 files changed, 73 insertions(+), 9 deletions(-) diff --git a/ts/components/CallingLobby.tsx b/ts/components/CallingLobby.tsx index 2bcbc0871b..a0b27bf4f4 100644 --- a/ts/components/CallingLobby.tsx +++ b/ts/components/CallingLobby.tsx @@ -39,11 +39,18 @@ export type PropsType = { | 'phoneNumber' | 'profileName' | 'sharedGroupNames' + | 'systemGivenName' + | 'systemNickname' | 'title' | 'type' | 'unblurredAvatarPath' >; - groupMembers?: Array>; + groupMembers?: Array< + Pick< + ConversationType, + 'id' | 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + > + >; hasLocalAudio: boolean; hasLocalVideo: boolean; i18n: LocalizerType; diff --git a/ts/components/CallingPreCallInfo.tsx b/ts/components/CallingPreCallInfo.tsx index ca0958cf79..3ecf92d632 100644 --- a/ts/components/CallingPreCallInfo.tsx +++ b/ts/components/CallingPreCallInfo.tsx @@ -25,6 +25,8 @@ export type PropsType = { | 'phoneNumber' | 'profileName' | 'sharedGroupNames' + | 'systemGivenName' + | 'systemNickname' | 'title' | 'type' | 'unblurredAvatarPath' @@ -34,10 +36,18 @@ export type PropsType = { ringMode: RingMode; // The following should only be set for group conversations. - groupMembers?: Array>; + groupMembers?: Array< + Pick< + ConversationType, + 'id' | 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + > + >; isCallFull?: boolean; peekedParticipants?: Array< - Pick + Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' | 'serviceId' + > >; }; diff --git a/ts/components/IncomingCallBar.tsx b/ts/components/IncomingCallBar.tsx index 0cfaeb14ea..d9431a90e4 100644 --- a/ts/components/IncomingCallBar.tsx +++ b/ts/components/IncomingCallBar.tsx @@ -53,8 +53,16 @@ export type PropsType = { } | { callMode: CallMode.Group; - otherMembersRung: Array>; - ringer: Pick; + otherMembersRung: Array< + Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + > + >; + ringer: Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + >; } ); @@ -96,8 +104,16 @@ function GroupCallMessage({ ringer, }: Readonly<{ i18n: LocalizerType; - otherMembersRung: Array>; - ringer: Pick; + otherMembersRung: Array< + Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + > + >; + ringer: Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + >; }>): JSX.Element { // As an optimization, we only process the first two names. const [first, second] = otherMembersRung diff --git a/ts/test-both/util/callingGetParticipantName_test.ts b/ts/test-both/util/callingGetParticipantName_test.ts index 33027f3397..a0356f56a3 100644 --- a/ts/test-both/util/callingGetParticipantName_test.ts +++ b/ts/test-both/util/callingGetParticipantName_test.ts @@ -20,4 +20,25 @@ describe('getParticipantName', () => { assert.strictEqual(getParticipantName(participant), 'Foo Bar'); }); + + it('returns system given name if available', () => { + const participant = { + firstName: 'Foo', + systemGivenName: 'Foo from that party', + title: 'Foo Bar', + }; + + assert.strictEqual(getParticipantName(participant), 'Foo from that party'); + }); + + it('returns system nickname if available', () => { + const participant = { + firstName: 'Foo', + systemGivenName: 'Foo from that party', + systemNickname: 'Foo-chan', + title: 'Foo Bar', + }; + + assert.strictEqual(getParticipantName(participant), 'Foo-chan'); + }); }); diff --git a/ts/util/callingGetParticipantName.ts b/ts/util/callingGetParticipantName.ts index df296ff15b..821f67d8e1 100644 --- a/ts/util/callingGetParticipantName.ts +++ b/ts/util/callingGetParticipantName.ts @@ -4,7 +4,17 @@ import type { ConversationType } from '../state/ducks/conversations'; export function getParticipantName( - participant: Readonly> + participant: Readonly< + Pick< + ConversationType, + 'firstName' | 'systemGivenName' | 'systemNickname' | 'title' + > + > ): string { - return participant.firstName || participant.title; + return ( + participant.systemNickname || + participant.systemGivenName || + participant.firstName || + participant.title + ); }