Skip to content

Commit 97f21b6

Browse files
committed
Send the outgoing m.room_key messages returned by shareRoomKey
I forgot this in #3122 :(. To be honest, I'm not sure how it ever worked.
1 parent 7e43311 commit 97f21b6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/rust-crypto/RoomEncryptor.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { Room } from "../models/room";
2222
import { logger, PrefixedLogger } from "../logger";
2323
import { KeyClaimManager } from "./KeyClaimManager";
2424
import { RoomMember } from "../models/room-member";
25+
import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor";
2526

2627
/**
2728
* RoomEncryptor: responsible for encrypting messages to a given room
@@ -38,6 +39,7 @@ export class RoomEncryptor {
3839
public constructor(
3940
private readonly olmMachine: OlmMachine,
4041
private readonly keyClaimManager: KeyClaimManager,
42+
private readonly outgoingRequestProcessor: OutgoingRequestProcessor,
4143
private readonly room: Room,
4244
private encryptionSettings: IContent,
4345
) {
@@ -97,10 +99,21 @@ export class RoomEncryptor {
9799
const userList = members.map((u) => new UserId(u.userId));
98100
await this.keyClaimManager.ensureSessionsForUsers(userList);
99101

102+
this.prefixedLogger.debug("Sessions for users are ready; now sharing room key");
103+
100104
const rustEncryptionSettings = new EncryptionSettings();
101105
/* FIXME historyVisibility, rotation, etc */
102106

103-
await this.olmMachine.shareRoomKey(new RoomId(this.room.roomId), userList, rustEncryptionSettings);
107+
const shareMessages = await this.olmMachine.shareRoomKey(
108+
new RoomId(this.room.roomId),
109+
userList,
110+
rustEncryptionSettings,
111+
);
112+
if (shareMessages) {
113+
for (const m of shareMessages) {
114+
await this.outgoingRequestProcessor.makeOutgoingRequest(m);
115+
}
116+
}
104117
}
105118

106119
/**

src/rust-crypto/rust-crypto.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,13 @@ export class RustCrypto implements CryptoBackend {
204204
if (existingEncryptor) {
205205
existingEncryptor.onCryptoEvent(config);
206206
} else {
207-
this.roomEncryptors[room.roomId] = new RoomEncryptor(this.olmMachine, this.keyClaimManager, room, config);
207+
this.roomEncryptors[room.roomId] = new RoomEncryptor(
208+
this.olmMachine,
209+
this.keyClaimManager,
210+
this.outgoingRequestProcessor,
211+
room,
212+
config,
213+
);
208214
}
209215

210216
// start tracking devices for any users already known to be in this room.

0 commit comments

Comments
 (0)