Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 56423d4

Browse files
authored
Restore createRoom.canEncryptToAllUsers (#10491)
1 parent 6ac366e commit 56423d4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/createRoom.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,9 @@ export async function canEncryptToAllUsers(client: MatrixClient, userIds: string
399399
try {
400400
const usersDeviceMap = await client.downloadKeys(userIds);
401401

402-
// There are no devices at all.
403-
if (usersDeviceMap.size === 0) return false;
404-
405402
for (const devices of usersDeviceMap.values()) {
406403
if (devices.size === 0) {
404+
// This user does not have any encryption-capable devices.
407405
return false;
408406
}
409407
}

test/createRoom-test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ describe("canEncryptToAllUsers", () => {
161161
client = mocked(stubClient());
162162
});
163163

164-
it("should return false if download keys does not return any user", async () => {
164+
it("should return true if userIds is empty", async () => {
165+
client.downloadKeys.mockResolvedValue(new Map());
166+
const result = await canEncryptToAllUsers(client, []);
167+
expect(result).toBe(true);
168+
});
169+
170+
it("should return true if download keys does not return any user", async () => {
165171
client.downloadKeys.mockResolvedValue(new Map());
166172
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
167-
expect(result).toBe(false);
173+
expect(result).toBe(true);
168174
});
169175

170176
it("should return false if none of the users has a device", async () => {

0 commit comments

Comments
 (0)