diff --git a/spec/unit/embedded.spec.ts b/spec/unit/embedded.spec.ts index fcc315b4574..cc866a4564e 100644 --- a/spec/unit/embedded.spec.ts +++ b/spec/unit/embedded.spec.ts @@ -40,7 +40,6 @@ import { SyncState } from "../../src/sync"; import { ICapabilities, RoomWidgetClient } from "../../src/embedded"; import { MatrixEvent } from "../../src/models/event"; import { ToDeviceBatch } from "../../src/models/ToDeviceMessage"; -import { DeviceInfo } from "../../src/crypto/deviceinfo"; import { sleep } from "../../src/utils"; const testOIDCToken = { @@ -731,8 +730,8 @@ describe("RoomWidgetClient", () => { const embeddedClient = client as RoomWidgetClient; await embeddedClient.encryptAndSendToDevices( [ - { userId: "@alice:example.org", deviceInfo: new DeviceInfo("aliceWeb") }, - { userId: "@bob:example.org", deviceInfo: new DeviceInfo("bobDesktop") }, + { userId: "@alice:example.org", deviceId: "aliceWeb" }, + { userId: "@bob:example.org", deviceId: "bobDesktop" }, ], payload, ); diff --git a/src/embedded.ts b/src/embedded.ts index b0cc4c158e8..d42ce531315 100644 --- a/src/embedded.ts +++ b/src/embedded.ts @@ -54,8 +54,6 @@ import { MatrixError } from "./http-api/errors.ts"; import { User } from "./models/user.ts"; import { Room } from "./models/room.ts"; import { ToDeviceBatch, ToDevicePayload } from "./models/ToDeviceMessage.ts"; -import { DeviceInfo } from "./crypto/deviceinfo.ts"; -import { IOlmDevice } from "./crypto/algorithms/megolm.ts"; import { MapWithDefault, recursiveMapToObject } from "./utils.ts"; import { TypedEventEmitter } from "./matrix.ts"; @@ -64,6 +62,17 @@ interface IStateEventRequest { stateKey?: string; } +export interface OlmDevice { + /** + * The user ID of the device owner. + */ + userId: string; + /** + * The device ID of the device. + */ + deviceId: string; +} + export interface ICapabilities { /** * Event types that this client expects to send. @@ -128,6 +137,7 @@ export enum RoomWidgetClientEvent { PendingEventsChanged = "PendingEvent.pendingEventsChanged", } export type EventHandlerMap = { [RoomWidgetClientEvent.PendingEventsChanged]: () => void }; + /** * A MatrixClient that routes its requests through the widget API instead of the * real CS API. @@ -466,13 +476,10 @@ export class RoomWidgetClient extends MatrixClient { await this.widgetApi.sendToDevice(eventType, false, recursiveMapToObject(contentMap)); } - public async encryptAndSendToDevices(userDeviceInfoArr: IOlmDevice[], payload: object): Promise { + public async encryptAndSendToDevices(userDeviceInfoArr: OlmDevice[], payload: object): Promise { // map: user Id → device Id → payload const contentMap: MapWithDefault> = new MapWithDefault(() => new Map()); - for (const { - userId, - deviceInfo: { deviceId }, - } of userDeviceInfoArr) { + for (const { userId, deviceId } of userDeviceInfoArr) { contentMap.getOrCreate(userId).set(deviceId, payload); }