@@ -2,12 +2,12 @@ import type { IUser, MediaCallActor, MediaCallActorType, MediaCallContact, Media
22import type { CallRole } from '@rocket.chat/media-signaling' ;
33import { Users } from '@rocket.chat/models' ;
44
5+ import { BroadcastActorAgent } from './BroadcastAgent' ;
56import type { IMediaCallAgent } from '../definition/IMediaCallAgent' ;
67import type { IMediaCallCastDirector } from '../definition/IMediaCallCastDirector' ;
78import type { GetActorContactOptions , MinimalUserData , MediaCallHeader } from '../definition/common' ;
89import { UserActorAgent } from '../internal/agents/UserActorAgent' ;
910import { logger } from '../logger' ;
10- import { BroadcastActorAgent } from './BroadcastAgent' ;
1111
1212type ContactList = Record < MediaCallActorType , MediaCallContact | null > ;
1313
@@ -89,11 +89,28 @@ export class MediaCallCastDirector implements IMediaCallCastDirector {
8989
9090 const list = user
9191 ? this . buildContactListForUser ( user , defaultContactInfo )
92- : this . buildContactListForExtension ( sipExtension , defaultContactInfo ) ;
92+ : await this . buildContactListForExtension ( sipExtension , defaultContactInfo ) ;
9393
9494 return this . getContactFromList ( list , options ) ;
9595 }
9696
97+ private async findUserByPhone ( phoneNumber : string ) : Promise < Pick < IUser , '_id' | 'name' | 'username' | 'freeSwitchExtension' > | null > {
98+ const users = await Users . findByPhone < Pick < IUser , '_id' | 'name' | 'username' | 'freeSwitchExtension' > > ( phoneNumber , {
99+ projection : { name : 1 , username : 1 , freeSwitchExtension : 1 } ,
100+ } ) . toArray ( ) ;
101+
102+ if ( ! users . length ) {
103+ return null ;
104+ }
105+
106+ if ( users . length > 1 ) {
107+ logger . warn ( { msg : 'Multiple users found for phone number, identity cannot be resolved' , phoneNumber } ) ;
108+ return null ;
109+ }
110+
111+ return users [ 0 ] ;
112+ }
113+
97114 public async getAgentForActorAndRole ( actor : MediaCallContact , role : CallRole ) : Promise < IMediaCallAgent | null > {
98115 if ( actor . type === 'user' ) {
99116 return this . getAgentForUserActorAndRole ( actor , role ) ;
@@ -141,10 +158,17 @@ export class MediaCallCastDirector implements IMediaCallCastDirector {
141158 } ;
142159 }
143160
144- protected buildContactListForExtension ( sipExtension : string , defaultContactInfo ?: MediaCallContactInformation ) : ContactList {
161+ protected async buildContactListForExtension (
162+ sipExtension : string ,
163+ defaultContactInfo ?: MediaCallContactInformation ,
164+ ) : Promise < ContactList > {
165+ const user = await this . findUserByPhone ( sipExtension ) ;
166+
145167 const data : Partial < MediaCallContact > = {
146168 ...defaultContactInfo ,
147169 ...( sipExtension && { sipExtension } ) ,
170+ ...( user ?. username && { username : user . username } ) ,
171+ ...( user ?. name && { displayName : user . name } ) ,
148172 } ;
149173
150174 return {
0 commit comments