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

Restore createRoom.canEncryptToAllUsers behaviour #10491

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,9 @@ export async function canEncryptToAllUsers(client: MatrixClient, userIds: string
try {
const usersDeviceMap = await client.downloadKeys(userIds);

// There are no devices at all.
if (usersDeviceMap.size === 0) return false;

for (const devices of usersDeviceMap.values()) {
if (devices.size === 0) {
// This user does not have any encryption-capable devices.
return false;
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/createRoom-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ describe("canEncryptToAllUsers", () => {
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());
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 () => {
Expand Down