Skip to content

Commit

Permalink
Back up keys when receiving/creating them
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Jul 19, 2023
1 parent f52ebad commit e885b88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/e2ee/CryptoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export class CryptoClient {
* @returns {Promise<void>} Resolves when complete.
*/
public async enableKeyBackup(info: IKeyBackupInfoRetrieved): Promise<void> {
this.client.on("to_device.decrypted", this.onToDeviceMessage);
await this.engine.enableKeyBackup(info);
}

Expand All @@ -302,5 +303,12 @@ export class CryptoClient {
*/
public disableKeyBackup(): void {
this.engine.disableKeyBackup();
this.client.removeListener("to_device.decrypted", this.onToDeviceMessage);
}

private readonly onToDeviceMessage = (msg: IToDeviceMessage): void => {
if (msg.type === "m.room_key") {
this.engine.machine.backupRoomKeys();
}
};
}
3 changes: 3 additions & 0 deletions src/e2ee/RustEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export class RustEngine {
const keysClaim = await this.machine.getMissingSessions(members);
if (keysClaim) {
await this.processKeysClaimRequest(keysClaim);
if (this.keyBackupVersion !== undefined) {
await this.machine.backupRoomKeys();
}
}
});

Expand Down

0 comments on commit e885b88

Please sign in to comment.