Merge pull request #5275 from matrix-org/travis/e2e/skip-if-not-possible

Wrap canEncryptToAllUsers in a try/catch to handle server errors
This commit is contained in:
Travis Ralston 2020-10-02 07:30:23 -06:00 committed by GitHub
commit fd441f7bba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,12 +275,17 @@ export async function _waitForMember(client: MatrixClient, roomId: string, userI
* can encrypt to.
*/
export async function canEncryptToAllUsers(client: MatrixClient, userIds: string[]) {
const usersDeviceMap = await client.downloadKeys(userIds);
// { "@user:host": { "DEVICE": {...}, ... }, ... }
return Object.values(usersDeviceMap).every((userDevices) =>
// { "DEVICE": {...}, ... }
Object.keys(userDevices).length > 0,
);
try {
const usersDeviceMap = await client.downloadKeys(userIds);
// { "@user:host": { "DEVICE": {...}, ... }, ... }
return Object.values(usersDeviceMap).every((userDevices) =>
// { "DEVICE": {...}, ... }
Object.keys(userDevices).length > 0,
);
} catch (e) {
console.error("Error determining if it's possible to encrypt to all users: ", e);
return false; // assume not
}
}
export async function ensureDMExists(client: MatrixClient, userId: string): Promise<string> {