Use asyncSomeParallel instead of asyncSome

This commit is contained in:
Florian Duros 2024-11-14 12:20:16 +01:00
parent 662fbd99e3
commit c0cca69836
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15
2 changed files with 4 additions and 18 deletions

View File

@ -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 {

View File

@ -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<b
return (
isEncryptionForceDisabled &&
!(await Promise.any(
client
.getRooms()
.map(({ roomId }) =>
crypto
.isEncryptionEnabledInRoom(roomId)
.then((encrypted) => (encrypted ? Promise.resolve(true) : Promise.reject(false))),
),
))
!(await asyncSomeParallel(client.getRooms(), ({ roomId }) => crypto.isEncryptionEnabledInRoom(roomId)))
);
};