Restore createRoom.canEncryptToAllUsers (#10491)
This commit is contained in:
parent
6ac366ee5a
commit
56423d4d53
2 changed files with 9 additions and 5 deletions
|
@ -399,11 +399,9 @@ export async function canEncryptToAllUsers(client: MatrixClient, userIds: string
|
||||||
try {
|
try {
|
||||||
const usersDeviceMap = await client.downloadKeys(userIds);
|
const usersDeviceMap = await client.downloadKeys(userIds);
|
||||||
|
|
||||||
// There are no devices at all.
|
|
||||||
if (usersDeviceMap.size === 0) return false;
|
|
||||||
|
|
||||||
for (const devices of usersDeviceMap.values()) {
|
for (const devices of usersDeviceMap.values()) {
|
||||||
if (devices.size === 0) {
|
if (devices.size === 0) {
|
||||||
|
// This user does not have any encryption-capable devices.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,10 +161,16 @@ describe("canEncryptToAllUsers", () => {
|
||||||
client = mocked(stubClient());
|
client = mocked(stubClient());
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false if download keys does not return any user", async () => {
|
it("should return true if userIds is empty", async () => {
|
||||||
|
client.downloadKeys.mockResolvedValue(new Map());
|
||||||
|
const result = await canEncryptToAllUsers(client, []);
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return true if download keys does not return any user", async () => {
|
||||||
client.downloadKeys.mockResolvedValue(new Map());
|
client.downloadKeys.mockResolvedValue(new Map());
|
||||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||||
expect(result).toBe(false);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false if none of the users has a device", async () => {
|
it("should return false if none of the users has a device", async () => {
|
||||||
|
|
Loading…
Reference in a new issue