Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Remove StopGadWidgetDriver.sendToDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Oct 14, 2024
1 parent d4a6c90 commit ef306d2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 98 deletions.
49 changes: 0 additions & 49 deletions src/stores/widgets/StopGapWidgetDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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<void> => {
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");
Expand Down
49 changes: 0 additions & 49 deletions test/stores/widgets/StopGapWidgetDriver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit ef306d2

Please sign in to comment.