First batch: Replace MatrixClient.isRoomEncrypted
by MatrixClient.CryptoApi.isEncryptionEnabledInRoom
(#28242)
* Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `DeviceListener.ts` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `Searching.ts` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `SlidingSyncManager.ts` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `EncryptionEvent.tsx` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `ReportEventDialog.tsx` * Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `RoomNotifications.tsx` * Fix MessagePanel-test.tsx * ReplaceReplace `MatrixCient..isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `shouldSkipSetupEncryption.ts` * Add missing `await` * Use `Promise.any` instead of `asyncSome` * Add `asyncSomeParallel` * Use `asyncSomeParallel` instead of `asyncSome`
This commit is contained in:
parent
c8e4ffe1dd
commit
d4ab40990b
16 changed files with 129 additions and 43 deletions
|
@ -328,6 +328,28 @@ export async function asyncSome<T>(values: Iterable<T>, predicate: (value: T) =>
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Async version of Array.some that runs all promises in parallel.
|
||||
* @param values
|
||||
* @param predicate
|
||||
*/
|
||||
export async function asyncSomeParallel<T>(
|
||||
values: Array<T>,
|
||||
predicate: (value: T) => Promise<boolean>,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
return await Promise.any<boolean>(
|
||||
values.map((value) =>
|
||||
predicate(value).then((result) => (result ? Promise.resolve(true) : Promise.reject(false))),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
// If the array is empty or all the promises are false, Promise.any will reject an AggregateError
|
||||
if (e instanceof AggregateError) return false;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export function filterBoolean<T>(values: Array<T | null | undefined>): T[] {
|
||||
return values.filter(Boolean) as T[];
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -16,7 +17,13 @@ import { shouldForceDisableEncryption } from "./shouldForceDisableEncryption";
|
|||
* @param client
|
||||
* @returns {boolean} true when we can skip settings up encryption
|
||||
*/
|
||||
export const shouldSkipSetupEncryption = (client: MatrixClient): boolean => {
|
||||
export const shouldSkipSetupEncryption = async (client: MatrixClient): Promise<boolean> => {
|
||||
const isEncryptionForceDisabled = shouldForceDisableEncryption(client);
|
||||
return isEncryptionForceDisabled && !client.getRooms().some((r) => client.isRoomEncrypted(r.roomId));
|
||||
const crypto = client.getCrypto();
|
||||
if (!crypto) return true;
|
||||
|
||||
return (
|
||||
isEncryptionForceDisabled &&
|
||||
!(await asyncSomeParallel(client.getRooms(), ({ roomId }) => crypto.isEncryptionEnabledInRoom(roomId)))
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue