Skip to content

Commit

Permalink
feat: Prepare for partial user fetching (#14875)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Mar 22, 2023
1 parent 96e848c commit 118dbfd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@emotion/react": "11.10.6",
"@types/eslint": "8.4.10",
"@wireapp/avs": "9.1.13",
"@wireapp/core": "39.3.3",
"@wireapp/core": "40.0.0",
"@wireapp/lru-cache": "3.8.1",
"@wireapp/react-ui-kit": "9.4.1",
"@wireapp/store-engine-dexie": "2.0.5",
Expand Down
23 changes: 5 additions & 18 deletions src/script/conversation/userClientsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,23 @@ import {QualifiedId} from '@wireapp/api-client/lib/user';
type UserClientsContainer<T> = {[userId: string]: T[]};
type QualifiedUserClientsContainer<T> = {[domain: string]: UserClientsContainer<T>};

function isQualifiedUserClients(obj: any): obj is QualifiedUserClientsContainer<unknown> {
if (typeof obj === 'object') {
const firstUserClientObject = Object.values(obj)?.[0];
if (typeof firstUserClientObject === 'object') {
const firstClientIdArray = Object.values(firstUserClientObject)[0];
return Array.isArray(firstClientIdArray);
}
}
return false;
}

function extractUserIds<T>(
userClients: UserClientsContainer<T>,
domain: string,
): {clients: T[]; userId: QualifiedId}[] {
return Object.entries(userClients).map(([id, clients]) => ({clients, userId: {domain, id}}));
}

/**
* Will flatten a container of users=>clients infos to an array
*
* @param userClients The UserClients (qualified or not) to flatten
* @return An array containing the qualified user Ids and the clients info
*/
export function flattenUserClientsQualifiedIds<T = unknown>(
userClients: UserClientsContainer<T> | QualifiedUserClientsContainer<T>,
userClients: QualifiedUserClientsContainer<T>,
): {clients: T[]; userId: QualifiedId}[] {
if (isQualifiedUserClients(userClients)) {
return Object.entries(userClients).reduce((ids, [domain, userClients]) => {
return [...ids, ...extractUserIds(userClients, domain)];
}, [] as {clients: T[]; userId: QualifiedId}[]);
}
return extractUserIds(userClients, '');
return Object.entries(userClients).reduce((ids, [domain, userClients]) => {
return [...ids, ...extractUserIds(userClients, domain)];
}, [] as {clients: T[]; userId: QualifiedId}[]);
}
5 changes: 3 additions & 2 deletions src/script/user/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,12 @@ export class UserService {
* @see https://staging-nginz-https.zinfra.io/swagger-ui/#!/users/users
* @example ['0bb84213-8cc2-4bb1-9e0b-b8dd522396d5', '15ede065-72b3-433a-9917-252f076ed031']
*/
getUsers(userIds: QualifiedId[]): Promise<APIClientUser[]> {
async getUsers(userIds: QualifiedId[]) {
if (userIds.length === 0) {
return Promise.resolve([]);
}
return this.apiClient.api.user.postListUsers({qualified_ids: userIds});
const {found} = await this.apiClient.api.user.postListUsers({qualified_ids: userIds});
return found;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4383,9 +4383,9 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/api-client@npm:^23.3.0":
version: 23.3.0
resolution: "@wireapp/api-client@npm:23.3.0"
"@wireapp/api-client@npm:^24.0.0":
version: 24.0.0
resolution: "@wireapp/api-client@npm:24.0.0"
dependencies:
"@wireapp/commons": ^5.0.4
"@wireapp/priority-queue": ^2.0.3
Expand All @@ -4398,7 +4398,7 @@ __metadata:
spark-md5: 3.0.2
tough-cookie: 4.1.2
ws: 8.11.0
checksum: b96cd363d012fa6bb6f562f9aa82dc80004bf74ab68fc81560d108c8de1e2f95fae5655a260fc9e26b9039000bedeb65ba202af9ed8e37d5688acbf196528811
checksum: 636aea6e382229cb57483e9db11c8c98b173de36b0d787b15279ee54a143be7ead7caa1cc0bc88cc6b8362ce0dd220cc3f5f3f84de9ad7d33edadc4c92c5be4e
languageName: node
linkType: hard

Expand Down Expand Up @@ -4451,11 +4451,11 @@ __metadata:
languageName: node
linkType: hard

"@wireapp/core@npm:39.3.3":
version: 39.3.3
resolution: "@wireapp/core@npm:39.3.3"
"@wireapp/core@npm:40.0.0":
version: 40.0.0
resolution: "@wireapp/core@npm:40.0.0"
dependencies:
"@wireapp/api-client": ^23.3.0
"@wireapp/api-client": ^24.0.0
"@wireapp/commons": ^5.0.4
"@wireapp/core-crypto": 0.7.0-rc.3
"@wireapp/cryptobox": 12.8.0
Expand All @@ -4472,7 +4472,7 @@ __metadata:
logdown: 3.3.1
long: ^5.2.0
uuidjs: 4.2.13
checksum: 2bbd4e86e91876a4bf17a535818a01e66ddecd3a2b8dedb5f6f8f18386d1ed5dbd2c94d40ba3b505845c6a2951dacfd42ce66727566c831531ee11947035b0e0
checksum: bea4f52b48d9e5b0cf453f62c01c9a7f6d47d98123ec18d2c0627290a233465ee93dd3db5bdeac21991823f015bf7cbb2e1a056e996e788385d33f0407738fad
languageName: node
linkType: hard

Expand Down Expand Up @@ -16788,7 +16788,7 @@ dexie@latest:
"@typescript-eslint/parser": ^5.55.0
"@wireapp/avs": 9.1.13
"@wireapp/copy-config": 2.0.10
"@wireapp/core": 39.3.3
"@wireapp/core": 40.0.0
"@wireapp/eslint-config": 2.1.1
"@wireapp/lru-cache": 3.8.1
"@wireapp/prettier-config": 0.5.2
Expand Down

0 comments on commit 118dbfd

Please sign in to comment.