From 1fda3607cb645c9bb01e89480a20f09b46ef83f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20G=C3=B3rka?= Date: Mon, 18 Sep 2023 13:24:36 +0200 Subject: [PATCH] runfix: identify mls capable client (#15841) * feat: bump core with correct mls public key type * runfix: identify client as mls capable * refactor: simplify return statement --- package.json | 2 +- src/script/client/ClientRepository.ts | 4 ++-- src/script/client/ClientUtils.ts | 10 +++++++++ src/script/self/SelfRepository.test.ts | 2 +- yarn.lock | 30 +++++++++++++------------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 55b7d33e5b0..e40056a05e3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "@datadog/browser-rum": "^4.49.0", "@emotion/react": "11.11.1", "@wireapp/avs": "9.3.7", - "@wireapp/core": "42.3.3", + "@wireapp/core": "42.3.4", "@wireapp/lru-cache": "3.8.1", "@wireapp/react-ui-kit": "9.9.5", "@wireapp/store-engine-dexie": "2.1.6", diff --git a/src/script/client/ClientRepository.ts b/src/script/client/ClientRepository.ts index 761d699efe9..44a712a030d 100644 --- a/src/script/client/ClientRepository.ts +++ b/src/script/client/ClientRepository.ts @@ -39,7 +39,7 @@ import {constructClientId, parseClientId} from './ClientIdUtil'; import {ClientMapper} from './ClientMapper'; import type {ClientService} from './ClientService'; import {ClientState} from './ClientState'; -import {wasClientActiveWithinLast4Weeks} from './ClientUtils'; +import {isClientMLSCapable, wasClientActiveWithinLast4Weeks} from './ClientUtils'; import {SIGN_OUT_REASON} from '../auth/SignOutReason'; import {PrimaryModal} from '../components/Modals/PrimaryModal'; @@ -589,6 +589,6 @@ export class ClientRepository { const selfClients = await this.getAllSelfClients(); //we consider client active if it was active within last 4 weeks const activeClients = selfClients.filter(wasClientActiveWithinLast4Weeks); - return activeClients.every(client => !!client.mls_public_keys); + return activeClients.every(isClientMLSCapable); } } diff --git a/src/script/client/ClientUtils.ts b/src/script/client/ClientUtils.ts index 35c45b28b65..e1d47100899 100644 --- a/src/script/client/ClientUtils.ts +++ b/src/script/client/ClientUtils.ts @@ -30,3 +30,13 @@ export const wasClientActiveWithinLast4Weeks = ({last_active: lastActiveISODate} const passedWeeksSinceLastActive = weeksPassedSinceDate(new Date(lastActiveISODate)); return passedWeeksSinceLastActive <= 4; }; + +/** + * Check if client is MLS-capable device. + * Client is considered MLS capable if it was registered and has uploaded MLS public keys. + * @param client - client to check + * @returns {boolean} + */ +export const isClientMLSCapable = ({mls_public_keys: mlsPublicKeys}: RegisteredClient): boolean => { + return Object.values(mlsPublicKeys).length > 0; +}; diff --git a/src/script/self/SelfRepository.test.ts b/src/script/self/SelfRepository.test.ts index 94632eb308e..7c62e0b22c8 100644 --- a/src/script/self/SelfRepository.test.ts +++ b/src/script/self/SelfRepository.test.ts @@ -91,7 +91,7 @@ const generateMLSFeaturesConfig = (migrationStatus: MLSMigrationStatus, supporte const createMockClientResponse = (doesSupportMLS = false, wasActiveWithinLast4Weeks = false) => { return { - mls_public_keys: doesSupportMLS ? {ed25519: 'key'} : undefined, + mls_public_keys: doesSupportMLS ? {ed25519: 'key'} : {}, last_active: wasActiveWithinLast4Weeks ? new Date().toISOString() : new Date(Date.now() - 5 * 7 * 24 * 60 * 60 * 1000).toISOString(), diff --git a/yarn.lock b/yarn.lock index e53e647f252..996650a32ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5364,9 +5364,9 @@ __metadata: languageName: node linkType: hard -"@wireapp/api-client@npm:^26.1.0": - version: 26.1.0 - resolution: "@wireapp/api-client@npm:26.1.0" +"@wireapp/api-client@npm:^26.1.1": + version: 26.1.1 + resolution: "@wireapp/api-client@npm:26.1.1" dependencies: "@wireapp/commons": ^5.1.3 "@wireapp/priority-queue": ^2.1.4 @@ -5380,7 +5380,7 @@ __metadata: spark-md5: 3.0.2 tough-cookie: 4.1.3 ws: 8.14.1 - checksum: a0008aa096641b5aaf224bb191e6bc25099875f3f13731dc8de6d747fb8cfe4c362b764c5a4f8f8757a53f95f5328dc74ed68ddec43f881fb8d648e25ba2ce18 + checksum: 788935f49f52c7b9c932f853a125f2ed4760eb62216f44c3ff12926b566502591f35bb3d163ed726acab48c8d6b3bb512ae3d2963440de28271d16e9648c9fcf languageName: node linkType: hard @@ -5433,11 +5433,11 @@ __metadata: languageName: node linkType: hard -"@wireapp/core@npm:42.3.3": - version: 42.3.3 - resolution: "@wireapp/core@npm:42.3.3" +"@wireapp/core@npm:42.3.4": + version: 42.3.4 + resolution: "@wireapp/core@npm:42.3.4" dependencies: - "@wireapp/api-client": ^26.1.0 + "@wireapp/api-client": ^26.1.1 "@wireapp/commons": ^5.1.3 "@wireapp/core-crypto": 1.0.0-rc.12 "@wireapp/cryptobox": 12.8.0 @@ -5446,7 +5446,7 @@ __metadata: "@wireapp/store-engine": 5.1.4 "@wireapp/store-engine-dexie": ^2.1.6 axios: 1.5.0 - bazinga64: ^6.3.0 + bazinga64: ^6.3.1 deepmerge-ts: 5.1.0 hash.js: 1.1.7 http-status-codes: 2.2.0 @@ -5454,7 +5454,7 @@ __metadata: logdown: 3.3.1 long: ^5.2.0 uuidjs: 4.2.13 - checksum: e7e4f9205bb5d68f589e46d9a2b57e4ecd374896923e0e6b2f3fa96b6579413076a0c9e03284d62818daa4db587573c5281120287fc78fa8e6ab7ea681446922 + checksum: 89fd8d273f140dc69e08691f07dcebabd8c271f0afbebf35e5431618fb2e3e62bfd4ae6f79aae69b3949f0142c20b3525188d63f449df05b7b2fda759b9ef064 languageName: node linkType: hard @@ -6526,10 +6526,10 @@ __metadata: languageName: node linkType: hard -"bazinga64@npm:^6.3.0": - version: 6.3.0 - resolution: "bazinga64@npm:6.3.0" - checksum: 8221f157a5d4bf53c2da03deaa4770da0a756b9f2829c2da5662519f211497e726b4994c5802179eb98d85d340e024c03522c69c9bbe6b21039b785aa20cd3a1 +"bazinga64@npm:^6.3.1": + version: 6.3.1 + resolution: "bazinga64@npm:6.3.1" + checksum: f720936b3919f8df3b903675a9557f36b5a959ec458d7536756b805a9a1e3c81d5d6a367adb0245b80e1ef870cd5f94491ac9566738016b5613b5e5e3bccce6e languageName: node linkType: hard @@ -18556,7 +18556,7 @@ __metadata: "@types/webpack-env": 1.18.1 "@wireapp/avs": 9.3.7 "@wireapp/copy-config": 2.1.7 - "@wireapp/core": 42.3.3 + "@wireapp/core": 42.3.4 "@wireapp/eslint-config": 3.0.4 "@wireapp/lru-cache": 3.8.1 "@wireapp/prettier-config": 0.6.3