Element-R: Starting a DMs with a user (#10673)
* Use `cli.getUserDeviceInfo` instead of `cli.downloadKeys` to create a room * Use `client.getCrypto().getUserDeviceInfo` instead of `client.getUserDeviceInfo` * Update `createRoom-test.ts` to use `getUserDeviceInfo` * Remove duplicate fieldpull/28217/head
parent
d7bb8043ea
commit
db40479910
|
@ -397,7 +397,10 @@ 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);
|
||||
const usersDeviceMap = await client.getCrypto()?.getUserDeviceInfo(userIds, true);
|
||||
if (!usersDeviceMap) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const devices of usersDeviceMap.values()) {
|
||||
if (devices.size === 0) {
|
||||
|
|
|
@ -15,8 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import { mocked, Mocked } from "jest-mock";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||
import { CryptoApi, MatrixClient, Device } from "matrix-js-sdk/src/matrix";
|
||||
import { RoomType } from "matrix-js-sdk/src/@types/event";
|
||||
|
||||
import { stubClient, setupAsyncStoreWithClient, mockPlatformPeg } from "./test-utils";
|
||||
|
@ -151,30 +150,32 @@ describe("canEncryptToAllUsers", () => {
|
|||
const user2Id = "@user2:example.com";
|
||||
|
||||
const devices = new Map([
|
||||
["DEV1", {} as unknown as DeviceInfo],
|
||||
["DEV2", {} as unknown as DeviceInfo],
|
||||
["DEV1", {} as unknown as Device],
|
||||
["DEV2", {} as unknown as Device],
|
||||
]);
|
||||
|
||||
let client: Mocked<MatrixClient>;
|
||||
let cryptoApi: Mocked<CryptoApi>;
|
||||
|
||||
beforeAll(() => {
|
||||
client = mocked(stubClient());
|
||||
cryptoApi = mocked(client.getCrypto()!);
|
||||
});
|
||||
|
||||
it("should return true if userIds is empty", async () => {
|
||||
client.downloadKeys.mockResolvedValue(new Map());
|
||||
cryptoApi.getUserDeviceInfo.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());
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(new Map());
|
||||
const result = await canEncryptToAllUsers(client, [user1Id, user2Id]);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false if none of the users has a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, new Map()],
|
||||
|
@ -185,7 +186,7 @@ describe("canEncryptToAllUsers", () => {
|
|||
});
|
||||
|
||||
it("should return false if some of the users don't have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, new Map()],
|
||||
[user2Id, devices],
|
||||
|
@ -196,7 +197,7 @@ describe("canEncryptToAllUsers", () => {
|
|||
});
|
||||
|
||||
it("should return true if all users have a device", async () => {
|
||||
client.downloadKeys.mockResolvedValue(
|
||||
cryptoApi.getUserDeviceInfo.mockResolvedValue(
|
||||
new Map([
|
||||
[user1Id, devices],
|
||||
[user2Id, devices],
|
||||
|
|
|
@ -120,6 +120,7 @@ export function createTestClient(): MatrixClient {
|
|||
downloadKeys: jest.fn(),
|
||||
},
|
||||
},
|
||||
getCrypto: jest.fn().mockReturnValue({ getUserDeviceInfo: jest.fn() }),
|
||||
|
||||
getPushActionsForEvent: jest.fn(),
|
||||
getRoom: jest.fn().mockImplementation((roomId) => mkStubRoom(roomId, "My room", client)),
|
||||
|
@ -233,7 +234,6 @@ export function createTestClient(): MatrixClient {
|
|||
}),
|
||||
|
||||
searchUserDirectory: jest.fn().mockResolvedValue({ limited: false, results: [] }),
|
||||
getCrypto: jest.fn(),
|
||||
} as unknown as MatrixClient;
|
||||
|
||||
client.reEmitter = new ReEmitter(client);
|
||||
|
|
Loading…
Reference in New Issue