commit c3e609f2550356016bd5030372d7e21858a46a64
parent 2b4f1fe94223ed6699a143b0eec1a4066f1d0d76
Author: MTRNord <mtrnord1@gmail.com>
Date: Mon, 8 May 2023 19:55:17 +0200
Make sure to share keys only on sending and to fix sync
Diffstat:
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/src/app/sdk/client.ts b/src/app/sdk/client.ts
@@ -391,11 +391,30 @@ export class MatrixClient extends EventEmitter {
await this.processRequest(request);
}
- await this.shareKeys();
+ await this.getMissingSessions();
this.outgoingRequestsBeingProcessed = false;
}
- public async shareKeys() {
+ public async shareKeysForRoom(room: Room) {
+ if (!this.isLoggedIn) {
+ throw Error("Not logged in");
+ }
+ if (!this.slidingSyncHostname) {
+ throw Error("Hostname must be set first");
+ }
+ if (!this.olmMachine) {
+ throw Error("Olm machine must be set first");
+ }
+ const encryptionSettings = room.getEncryptionSettings();
+ if (encryptionSettings) {
+ const requests = await this.olmMachine.shareRoomKey(new RoomId(room.roomID), room.getJoinedMemberIDs().map(id => new UserId(id)), encryptionSettings);
+ for (const request of requests) {
+ await this.processRequest(request);
+ }
+ }
+ }
+
+ public async getMissingSessions() {
if (!this.isLoggedIn) {
throw Error("Not logged in");
}
@@ -418,17 +437,6 @@ export class MatrixClient extends EventEmitter {
await this.processRequest(request);
}
- // TODO: This only should be done on sending a message in the room
- for (const room of encryptedRooms) {
- const encryptionSettings = room.getEncryptionSettings();
- if (encryptionSettings) {
- const requests = await this.olmMachine.shareRoomKey(new RoomId(room.roomID), room.getJoinedMemberIDs().map(id => new UserId(id)), encryptionSettings);
- for (const request of requests) {
- await this.processRequest(request);
- }
- }
- }
-
this.missingSessionsBeingRequested = false;
}
@@ -677,6 +685,7 @@ export class MatrixClient extends EventEmitter {
lists_ranges[list] = [[Math.max(minimum - 10, 0), maximum + 10]];
}
}
+ lists_ranges["e2ee"] = lists_ranges["overview"];
}
diff --git a/src/app/sdk/room.ts b/src/app/sdk/room.ts
@@ -247,7 +247,8 @@ export class Room extends EventEmitter {
return json.event_id;
} else {
console.log("Sending encrypted message");
- await this.client.shareKeys();
+ await this.client.getMissingSessions();
+ await this.client.shareKeysForRoom(this);
const encrypted = await this.client.olmMachine?.encryptRoomEvent(
new RoomId(this.roomID),
"m.room.message",
@@ -294,7 +295,8 @@ export class Room extends EventEmitter {
return json.event_id;
} else {
console.log("Sending encrypted message2");
- await this.client.shareKeys();
+ await this.client.getMissingSessions();
+ await this.client.shareKeysForRoom(this);
const encrypted = await this.client.olmMachine?.encryptRoomEvent(
new RoomId(this.roomID),
"m.room.message",