diff --git a/src/rust-crypto/KeyClaimManager.ts b/src/rust-crypto/KeyClaimManager.ts index 0479bfa43c1..9df8f89daf9 100644 --- a/src/rust-crypto/KeyClaimManager.ts +++ b/src/rust-crypto/KeyClaimManager.ts @@ -54,7 +54,12 @@ export class KeyClaimManager { // The Rust-SDK requires that we only have one getMissingSessions process in flight at once. This little dance // ensures that, by only having one call to ensureSessionsForUsersInner active at once (and making them // queue up in order). - const prom = this.currentClaimPromise.finally(() => this.ensureSessionsForUsersInner(userList)); + const prom = this.currentClaimPromise + .catch(() => { + // any errors in the previous claim will have been reported already, so there is nothing to do here. + // we just throw away the error and start anew. + }) + .then(() => this.ensureSessionsForUsersInner(userList)); this.currentClaimPromise = prom; return prom; } diff --git a/src/rust-crypto/RoomEncryptor.ts b/src/rust-crypto/RoomEncryptor.ts index acd0e9ff033..381ea61786f 100644 --- a/src/rust-crypto/RoomEncryptor.ts +++ b/src/rust-crypto/RoomEncryptor.ts @@ -22,6 +22,7 @@ import { Room } from "../models/room"; import { logger, PrefixedLogger } from "../logger"; import { KeyClaimManager } from "./KeyClaimManager"; import { RoomMember } from "../models/room-member"; +import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor"; /** * RoomEncryptor: responsible for encrypting messages to a given room @@ -38,6 +39,7 @@ export class RoomEncryptor { public constructor( private readonly olmMachine: OlmMachine, private readonly keyClaimManager: KeyClaimManager, + private readonly outgoingRequestProcessor: OutgoingRequestProcessor, private readonly room: Room, private encryptionSettings: IContent, ) { @@ -97,10 +99,21 @@ export class RoomEncryptor { const userList = members.map((u) => new UserId(u.userId)); await this.keyClaimManager.ensureSessionsForUsers(userList); + this.prefixedLogger.debug("Sessions for users are ready; now sharing room key"); + const rustEncryptionSettings = new EncryptionSettings(); /* FIXME historyVisibility, rotation, etc */ - await this.olmMachine.shareRoomKey(new RoomId(this.room.roomId), userList, rustEncryptionSettings); + const shareMessages = await this.olmMachine.shareRoomKey( + new RoomId(this.room.roomId), + userList, + rustEncryptionSettings, + ); + if (shareMessages) { + for (const m of shareMessages) { + await this.outgoingRequestProcessor.makeOutgoingRequest(m); + } + } } /** diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 2377b8a2177..8b62e9e6c4a 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -204,7 +204,13 @@ export class RustCrypto implements CryptoBackend { if (existingEncryptor) { existingEncryptor.onCryptoEvent(config); } else { - this.roomEncryptors[room.roomId] = new RoomEncryptor(this.olmMachine, this.keyClaimManager, room, config); + this.roomEncryptors[room.roomId] = new RoomEncryptor( + this.olmMachine, + this.keyClaimManager, + this.outgoingRequestProcessor, + room, + config, + ); } // start tracking devices for any users already known to be in this room.