From c0cca69836f57b71d2147ee042ebc899d7096e1b Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 14 Nov 2024 12:20:16 +0100 Subject: [PATCH] Use `asyncSomeParallel` instead of `asyncSome` --- src/DeviceListener.ts | 11 ++--------- src/utils/crypto/shouldSkipSetupEncryption.ts | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index cc8fa3a41b..4f47cd7eac 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -46,6 +46,7 @@ import SettingsStore, { CallbackFn } from "./settings/SettingsStore"; import { UIFeature } from "./settings/UIFeature"; import { isBulkUnverifiedDeviceReminderSnoozed } from "./utils/device/snoozeBulkUnverifiedDeviceReminder"; import { getUserDeviceIds } from "./utils/crypto/deviceInfo"; +import { asyncSomeParallel } from "./utils/arrays.ts"; const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000; @@ -249,15 +250,7 @@ export default class DeviceListener { const cryptoApi = cli?.getCrypto(); if (!cli || !cryptoApi) return false; - return await Promise.any( - cli - .getRooms() - .map(({ roomId }) => - cryptoApi - .isEncryptionEnabledInRoom(roomId) - .then((encrypted) => (encrypted ? Promise.resolve(true) : Promise.reject(false))), - ), - ); + return await asyncSomeParallel(cli.getRooms(), ({ roomId }) => cryptoApi.isEncryptionEnabledInRoom(roomId)); } private recheck(): void { diff --git a/src/utils/crypto/shouldSkipSetupEncryption.ts b/src/utils/crypto/shouldSkipSetupEncryption.ts index e2e3662902..d4dbb27d1b 100644 --- a/src/utils/crypto/shouldSkipSetupEncryption.ts +++ b/src/utils/crypto/shouldSkipSetupEncryption.ts @@ -9,6 +9,7 @@ Please see LICENSE files in the repository root for full details. import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { shouldForceDisableEncryption } from "./shouldForceDisableEncryption"; +import { asyncSomeParallel } from "../arrays.ts"; /** * If encryption is force disabled AND the user is not in any encrypted rooms @@ -23,14 +24,6 @@ export const shouldSkipSetupEncryption = async (client: MatrixClient): Promise - crypto - .isEncryptionEnabledInRoom(roomId) - .then((encrypted) => (encrypted ? Promise.resolve(true) : Promise.reject(false))), - ), - )) + !(await asyncSomeParallel(client.getRooms(), ({ roomId }) => crypto.isEncryptionEnabledInRoom(roomId))) ); };