diff --git a/src/client.ts b/src/client.ts index e9cf8fff1..975de9f01 100644 --- a/src/client.ts +++ b/src/client.ts @@ -40,7 +40,6 @@ import { sleep } from './utils'; import { Direction, EventTimeline } from "./models/event-timeline"; import { IActionsObject, PushProcessor } from "./pushprocessor"; import { AutoDiscovery, AutoDiscoveryAction } from "./autodiscovery"; -import { IEncryptAndSendToDevicesResult } from "./crypto"; import * as olmlib from "./crypto/olmlib"; import { decodeBase64, encodeBase64 } from "./crypto/olmlib"; import { IExportedDevice as IExportedOlmDevice } from "./crypto/OlmDevice"; @@ -2583,7 +2582,7 @@ export class MatrixClient extends TypedEventEmitter[], payload: object, - ): Promise { + ): Promise { if (!this.crypto) { throw new Error("End-to-End encryption disabled"); } diff --git a/src/crypto/algorithms/megolm.ts b/src/crypto/algorithms/megolm.ts index 50fed9ebb..e82008fd8 100644 --- a/src/crypto/algorithms/megolm.ts +++ b/src/crypto/algorithms/megolm.ts @@ -606,19 +606,19 @@ class MegolmEncryption extends EncryptionAlgorithm { private encryptAndSendKeysToDevices( session: OutboundSessionInfo, chainIndex: number, - userDeviceMap: IOlmDevice[], + devices: IOlmDevice[], payload: IPayload, ): Promise { return this.crypto.encryptAndSendToDevices( - userDeviceMap, + devices, payload, - ).then(({ toDeviceBatch, deviceInfoByUserIdAndDeviceId }) => { + ).then(() => { // store that we successfully uploaded the keys of the current slice - for (const msg of toDeviceBatch.batch) { + for (const device of devices) { session.markSharedWithDevice( - msg.userId, - msg.deviceId, - deviceInfoByUserIdAndDeviceId.get(msg.userId).get(msg.deviceId).getIdentityKey(), + device.userId, + device.deviceInfo.deviceId, + device.deviceInfo.getIdentityKey(), chainIndex, ); } diff --git a/src/crypto/index.ts b/src/crypto/index.ts index ff5ab43fe..451d2d8c8 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -212,11 +212,6 @@ export interface IEncryptedContent { } /* eslint-enable camelcase */ -export interface IEncryptAndSendToDevicesResult { - toDeviceBatch: ToDeviceBatch; - deviceInfoByUserIdAndDeviceId: Map>; -} - export enum CryptoEvent { DeviceVerificationChanged = "deviceVerificationChanged", UserTrustStatusChanged = "userTrustStatusChanged", @@ -3129,12 +3124,11 @@ export class Crypto extends TypedEventEmitter[], payload: object, - ): Promise { + ): Promise { const toDeviceBatch: ToDeviceBatch = { eventType: EventType.RoomMessageEncrypted, batch: [], }; - const deviceInfoByUserIdAndDeviceId = new Map>(); try { await Promise.all(userDeviceInfoArr.map(async ({ userId, deviceInfo }) => { @@ -3145,17 +3139,6 @@ export class Crypto extends TypedEventEmitter(); - deviceInfoByUserIdAndDeviceId.set(userId, userIdDeviceInfo); - } - - // We hold by reference, this updates deviceInfoByUserIdAndDeviceId[userId] - userIdDeviceInfo.set(deviceId, deviceInfo); - toDeviceBatch.batch.push({ userId, deviceId, @@ -3193,7 +3176,6 @@ export class Crypto extends TypedEventEmitter