1818 */
1919
2020import ko from 'knockout' ;
21- import { ClientType , PublicClient , RegisteredClient } from '@wireapp/api-client/src/client/' ;
22- import { USER_EVENT , UserClientAddEvent , UserClientRemoveEvent } from '@wireapp/api-client/src/event/' ;
21+ import { ClientType , PublicClient , QualifiedPublicClients , RegisteredClient } from '@wireapp/api-client/src/client/' ;
22+ import { USER_EVENT , UserClientAddEvent , UserClientRemoveEvent } from '@wireapp/api-client/src/event' ;
23+ import { QualifiedId } from '@wireapp/api-client/src/user/' ;
2324import { Runtime } from '@wireapp/commons' ;
2425import { amplify } from 'amplify' ;
2526import { WebAppEvents } from '@wireapp/webapp-events' ;
@@ -43,6 +44,8 @@ import {ClientError} from '../error/ClientError';
4344import { ClientRecord } from '../storage' ;
4445import { ClientState } from './ClientState' ;
4546
47+ export type QualifiedUserClientMap = { [ domain : string ] : { [ userId : string ] : ClientEntity [ ] } } ;
48+
4649export class ClientRepository {
4750 private readonly logger : Logger ;
4851 public selfUser : ko . Observable < User > ;
@@ -342,29 +345,34 @@ export class ClientRepository {
342345 * Retrieves meta information about all the clients of a given user.
343346 * @note If you want to get very detailed information about the devices from the own user, then use `getClients()`.
344347 *
345- * @param userId User ID to retrieve client information for
348+ * @param userIds User IDs to retrieve client information for
346349 * @param updateClients Automatically update the clients
347350 * @returns Resolves with an array of client entities
348351 */
349- async getClientsByUserIds ( userId : string [ ] , updateClients : false ) : Promise < Record < string , PublicClient [ ] > > ;
350- async getClientsByUserIds ( userId : string [ ] , updateClients ?: boolean ) : Promise < Record < string , ClientEntity [ ] > > ;
352+ async getClientsByUserIds ( userIds : ( QualifiedId | string ) [ ] , updateClients : true ) : Promise < QualifiedUserClientMap > ;
353+ async getClientsByUserIds ( userIds : ( QualifiedId | string ) [ ] , updateClients : false ) : Promise < QualifiedPublicClients > ;
351354 async getClientsByUserIds (
352- userId : string [ ] ,
353- updateClients : boolean = true ,
354- ) : Promise < Record < string , ClientEntity [ ] > | Record < string , PublicClient [ ] > > {
355- const userClientsMap = await this . clientService . getClientsByUserIds ( userId ) ;
355+ userIds : ( QualifiedId | string ) [ ] ,
356+ updateClients : boolean ,
357+ ) : Promise < QualifiedPublicClients | QualifiedUserClientMap > {
358+ const userClientsMap = await this . clientService . getClientsByUserIds ( userIds ) ;
356359
357360 if ( updateClients ) {
358- const clientEntityMap : Record < string , ClientEntity [ ] > = { } ;
361+ const clientEntityMap : QualifiedUserClientMap = { } ;
359362 await Promise . all (
360- Object . entries ( userClientsMap . none ) . map ( async ( [ userId , clients ] ) => {
361- clientEntityMap [ userId ] = await this . updateClientsOfUserById ( userId , clients ) ;
362- } ) ,
363+ Object . entries ( userClientsMap ) . map ( ( [ domain , userClientMap ] ) =>
364+ Object . entries ( userClientMap ) . map ( async ( [ userId , clients ] ) => {
365+ if ( ! clientEntityMap [ domain ] ) {
366+ clientEntityMap [ domain ] = { } ;
367+ }
368+ clientEntityMap [ domain ] [ userId ] = await this . updateClientsOfUserById ( userId , clients ) ;
369+ } ) ,
370+ ) ,
363371 ) ;
364372 return clientEntityMap ;
365373 }
366374
367- return userClientsMap . none ;
375+ return userClientsMap ;
368376 }
369377
370378 private async getClientByUserIdFromDb ( requestedUserId : string ) : Promise < ClientRecord [ ] > {
0 commit comments