Skip to content

Commit

Permalink
Handle immediate outgoing backup requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewFerr committed Aug 2, 2023
1 parent bfe6c37 commit 64463f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/e2ee/CryptoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class CryptoClient {
public async enableKeyBackup(info: IKeyBackupInfoRetrieved): Promise<void> {
this.client.on("to_device.decrypted", this.onToDeviceMessage);
await this.engine.enableKeyBackup(info);
this.engine.backupRoomKeys();
}

/**
Expand All @@ -308,7 +309,7 @@ export class CryptoClient {

private readonly onToDeviceMessage = (msg: IToDeviceMessage): void => {
if (msg.type === "m.room_key") {
this.engine.machine.backupRoomKeys();
this.engine.backupRoomKeys();
}
};
}
7 changes: 7 additions & 0 deletions src/e2ee/RustEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ export class RustEngine {
await this.machine.disableBackup();
}

public async backupRoomKeys() {
const request = await this.machine.backupRoomKeys();
if (request) {
await this.processKeysBackupRequest(request);
}
}

private async processKeysClaimRequest(request: KeysClaimRequest) {
const resp = await this.client.doRequest("POST", "/_matrix/client/v3/keys/claim", null, JSON.parse(request.body));
await this.machine.markRequestAsSent(request.id, request.type, JSON.stringify(resp));
Expand Down

0 comments on commit 64463f4

Please sign in to comment.