diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 88e79d97f2..bf4ee16b5d 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -414,55 +414,6 @@ export class StopGapWidgetDriver extends WidgetDriver { await client._unstable_updateDelayedEvent(delayId, action); } - public async sendToDevice( - eventType: string, - encrypted: boolean, - contentMap: { [userId: string]: { [deviceId: string]: object } }, - ): Promise { - const client = MatrixClientPeg.safeGet(); - - if (encrypted) { - const deviceInfoMap = await client.crypto!.deviceList.downloadKeys(Object.keys(contentMap), false); - - await Promise.all( - Object.entries(contentMap).flatMap(([userId, userContentMap]) => - Object.entries(userContentMap).map(async ([deviceId, content]): Promise => { - const devices = deviceInfoMap.get(userId); - if (!devices) return; - - if (deviceId === "*") { - // Send the message to all devices we have keys for - await client.encryptAndSendToDevices( - Array.from(devices.values()).map((deviceInfo) => ({ - userId, - deviceInfo, - })), - content, - ); - } else if (devices.has(deviceId)) { - // Send the message to a specific device - await client.encryptAndSendToDevices( - [{ userId, deviceInfo: devices.get(deviceId)! }], - content, - ); - } - }), - ), - ); - } else { - await client.queueToDevice({ - eventType, - batch: Object.entries(contentMap).flatMap(([userId, userContentMap]) => - Object.entries(userContentMap).map(([deviceId, content]) => ({ - userId, - deviceId, - payload: content, - })), - ), - }); - } - } - private pickRooms(roomIds?: (string | Symbols.AnyRoom)[]): Room[] { const client = MatrixClientPeg.get(); if (!client) throw new Error("Not attached to a client"); diff --git a/test/stores/widgets/StopGapWidgetDriver-test.ts b/test/stores/widgets/StopGapWidgetDriver-test.ts index 6e3387e216..4c2b86d211 100644 --- a/test/stores/widgets/StopGapWidgetDriver-test.ts +++ b/test/stores/widgets/StopGapWidgetDriver-test.ts @@ -18,7 +18,6 @@ import { MsgType, RelationType, } from "matrix-js-sdk/src/matrix"; -import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo"; import { Widget, MatrixWidgetType, @@ -171,54 +170,6 @@ describe("StopGapWidgetDriver", () => { expect(listener).toHaveBeenCalledWith(openIdUpdate); }); - describe("sendToDevice", () => { - const contentMap = { - "@alice:example.org": { - "*": { - hello: "alice", - }, - }, - "@bob:example.org": { - bobDesktop: { - hello: "bob", - }, - }, - }; - - let driver: WidgetDriver; - - beforeEach(() => { - driver = mkDefaultDriver(); - }); - - it("sends unencrypted messages", async () => { - await driver.sendToDevice("org.example.foo", false, contentMap); - expect(client.queueToDevice.mock.calls).toMatchSnapshot(); - }); - - it("sends encrypted messages", async () => { - const aliceWeb = new DeviceInfo("aliceWeb"); - const aliceMobile = new DeviceInfo("aliceMobile"); - const bobDesktop = new DeviceInfo("bobDesktop"); - - mocked(client.crypto!.deviceList).downloadKeys.mockResolvedValue( - new Map([ - [ - "@alice:example.org", - new Map([ - ["aliceWeb", aliceWeb], - ["aliceMobile", aliceMobile], - ]), - ], - ["@bob:example.org", new Map([["bobDesktop", bobDesktop]])], - ]), - ); - - await driver.sendToDevice("org.example.foo", true, contentMap); - expect(client.encryptAndSendToDevices.mock.calls).toMatchSnapshot(); - }); - }); - describe("getTurnServers", () => { let driver: WidgetDriver; diff --git a/test/stores/widgets/__snapshots__/StopGapWidgetDriver-test.ts.snap b/test/stores/widgets/__snapshots__/StopGapWidgetDriver-test.ts.snap deleted file mode 100644 index da3c19d567..0000000000 --- a/test/stores/widgets/__snapshots__/StopGapWidgetDriver-test.ts.snap +++ /dev/null @@ -1,82 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`StopGapWidgetDriver sendToDevice sends encrypted messages 1`] = ` -[ - [ - [ - { - "deviceInfo": DeviceInfo { - "algorithms": [], - "deviceId": "aliceWeb", - "keys": {}, - "known": false, - "signatures": {}, - "unsigned": {}, - "verified": 0, - }, - "userId": "@alice:example.org", - }, - { - "deviceInfo": DeviceInfo { - "algorithms": [], - "deviceId": "aliceMobile", - "keys": {}, - "known": false, - "signatures": {}, - "unsigned": {}, - "verified": 0, - }, - "userId": "@alice:example.org", - }, - ], - { - "hello": "alice", - }, - ], - [ - [ - { - "deviceInfo": DeviceInfo { - "algorithms": [], - "deviceId": "bobDesktop", - "keys": {}, - "known": false, - "signatures": {}, - "unsigned": {}, - "verified": 0, - }, - "userId": "@bob:example.org", - }, - ], - { - "hello": "bob", - }, - ], -] -`; - -exports[`StopGapWidgetDriver sendToDevice sends unencrypted messages 1`] = ` -[ - [ - { - "batch": [ - { - "deviceId": "*", - "payload": { - "hello": "alice", - }, - "userId": "@alice:example.org", - }, - { - "deviceId": "bobDesktop", - "payload": { - "hello": "bob", - }, - "userId": "@bob:example.org", - }, - ], - "eventType": "org.example.foo", - }, - ], -] -`; diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 467c8b7909..205f80130d 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -214,7 +214,6 @@ export function createTestClient(): MatrixClient { makeTxnId: jest.fn().mockImplementation(() => `t${txnId++}`), sendToDevice: jest.fn().mockResolvedValue(undefined), queueToDevice: jest.fn().mockResolvedValue(undefined), - encryptAndSendToDevices: jest.fn().mockResolvedValue(undefined), cancelPendingEvent: jest.fn(), getMediaHandler: jest.fn().mockReturnValue({