Fix detection of encryption for all users in a room (#10487)

This commit is contained in:
Michael Weimann 2023-03-31 09:43:47 +02:00 committed by GitHub
parent ff1468b6d3
commit dddef858f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 29 deletions

View file

@ -398,16 +398,21 @@ export default async function createRoom(opts: IOpts): Promise<string | null> {
export async function canEncryptToAllUsers(client: MatrixClient, userIds: string[]): Promise<boolean> {
try {
const usersDeviceMap = await client.downloadKeys(userIds);
// { "@user:host": { "DEVICE": {...}, ... }, ... }
return Object.values(usersDeviceMap).every(
(userDevices) =>
// { "DEVICE": {...}, ... }
Object.keys(userDevices).length > 0,
);
// There are no devices at all.
if (usersDeviceMap.size === 0) return false;
for (const devices of usersDeviceMap.values()) {
if (devices.size === 0) {
return false;
}
}
} catch (e) {
logger.error("Error determining if it's possible to encrypt to all users: ", e);
return false; // assume not
}
return true;
}
// Similar to ensureDMExists but also adds creation content