From 7ec5450fa3911270ac2c5288fbabee454abe2c95 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Thu, 14 Nov 2024 11:25:00 +0100 Subject: [PATCH] Use `Promise.any` instead of `asyncSome` --- src/DeviceListener.ts | 13 ++++++++++--- src/utils/crypto/shouldSkipSetupEncryption.ts | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index 5568e3f0274..cc8fa3a41b3 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -46,7 +46,6 @@ import SettingsStore, { CallbackFn } from "./settings/SettingsStore"; import { UIFeature } from "./settings/UIFeature"; import { isBulkUnverifiedDeviceReminderSnoozed } from "./utils/device/snoozeBulkUnverifiedDeviceReminder"; import { getUserDeviceIds } from "./utils/crypto/deviceInfo"; -import { asyncSome } from "./utils/arrays.ts"; const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000; @@ -241,7 +240,7 @@ export default class DeviceListener { return this.keyBackupInfo; } - private shouldShowSetupEncryptionToast(): Promise | boolean { + private async shouldShowSetupEncryptionToast(): Promise { // If we're in the middle of a secret storage operation, we're likely // modifying the state involved here, so don't add new toasts to setup. if (isSecretStorageBeingAccessed()) return false; @@ -250,7 +249,15 @@ export default class DeviceListener { const cryptoApi = cli?.getCrypto(); if (!cli || !cryptoApi) return false; - return asyncSome(cli.getRooms(), ({ roomId }) => cryptoApi.isEncryptionEnabledInRoom(roomId)); + return await Promise.any( + cli + .getRooms() + .map(({ roomId }) => + cryptoApi + .isEncryptionEnabledInRoom(roomId) + .then((encrypted) => (encrypted ? Promise.resolve(true) : Promise.reject(false))), + ), + ); } private recheck(): void { diff --git a/src/utils/crypto/shouldSkipSetupEncryption.ts b/src/utils/crypto/shouldSkipSetupEncryption.ts index 3d5eef90348..e2e36629027 100644 --- a/src/utils/crypto/shouldSkipSetupEncryption.ts +++ b/src/utils/crypto/shouldSkipSetupEncryption.ts @@ -9,7 +9,6 @@ Please see LICENSE files in the repository root for full details. import { MatrixClient } from "matrix-js-sdk/src/matrix"; import { shouldForceDisableEncryption } from "./shouldForceDisableEncryption"; -import { asyncSome } from "../arrays.ts"; /** * If encryption is force disabled AND the user is not in any encrypted rooms @@ -24,6 +23,14 @@ export const shouldSkipSetupEncryption = async (client: MatrixClient): Promise crypto.isEncryptionEnabledInRoom(roomId))) + !(await Promise.any( + client + .getRooms() + .map(({ roomId }) => + crypto + .isEncryptionEnabledInRoom(roomId) + .then((encrypted) => (encrypted ? Promise.resolve(true) : Promise.reject(false))), + ), + )) ); };