1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Merge pull request #1577 from uhoreg/always_queue_backup

Queue keys for backup even if backup isn't enabled yet
This commit is contained in:
Hubert Chathi
2021-01-15 12:28:06 -05:00
committed by GitHub
2 changed files with 19 additions and 31 deletions

View File

@@ -369,17 +369,11 @@ MegolmEncryption.prototype._prepareNewSession = async function() {
key.key, {ed25519: this._olmDevice.deviceEd25519Key}, key.key, {ed25519: this._olmDevice.deviceEd25519Key},
); );
if (this._crypto.backupInfo) { // don't wait for it to complete
// don't wait for it to complete this._crypto.backupGroupSession(
this._crypto.backupGroupSession( this._roomId, this._olmDevice.deviceCurve25519Key, [],
this._roomId, this._olmDevice.deviceCurve25519Key, [], sessionId, key.key,
sessionId, key.key, );
).catch((e) => {
// This throws if the upload failed, but this is fine
// since it will have written it to the db and will retry.
logger.log("Failed to back up megolm session", e);
});
}
return new OutboundSessionInfo(sessionId); return new OutboundSessionInfo(sessionId);
}; };
@@ -1347,18 +1341,12 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) {
} }
}); });
}).then(() => { }).then(() => {
if (this._crypto.backupInfo) { // don't wait for the keys to be backed up for the server
// don't wait for the keys to be backed up for the server this._crypto.backupGroupSession(
this._crypto.backupGroupSession( content.room_id, senderKey, forwardingKeyChain,
content.room_id, senderKey, forwardingKeyChain, content.session_id, content.session_key, keysClaimed,
content.session_id, content.session_key, keysClaimed, exportFormat,
exportFormat, );
).catch((e) => {
// This throws if the upload failed, but this is fine
// since it will have written it to the db and will retry.
logger.log("Failed to back up megolm session", e);
});
}
}).catch((e) => { }).catch((e) => {
logger.error(`Error handling m.room_key_event: ${e}`); logger.error(`Error handling m.room_key_event: ${e}`);
}); });
@@ -1564,7 +1552,7 @@ MegolmDecryption.prototype.importRoomKey = function(session, opts = {}) {
true, true,
opts.untrusted ? { untrusted: opts.untrusted } : {}, opts.untrusted ? { untrusted: opts.untrusted } : {},
).then(() => { ).then(() => {
if (this._crypto.backupInfo && opts.source !== "backup") { if (opts.source !== "backup") {
// don't wait for it to complete // don't wait for it to complete
this._crypto.backupGroupSession( this._crypto.backupGroupSession(
session.room_id, session.room_id,

View File

@@ -2884,18 +2884,18 @@ Crypto.prototype.backupGroupSession = async function(
sessionId, sessionKey, keysClaimed, sessionId, sessionKey, keysClaimed,
exportFormat, exportFormat,
) { ) {
if (!this.backupInfo) {
throw new Error("Key backups are not enabled");
}
await this._cryptoStore.markSessionsNeedingBackup([{ await this._cryptoStore.markSessionsNeedingBackup([{
senderKey: senderKey, senderKey: senderKey,
sessionId: sessionId, sessionId: sessionId,
}]); }]);
// don't wait for this to complete: it will delay so if (this.backupInfo) {
// happens in the background // don't wait for this to complete: it will delay so
this.scheduleKeyBackupSend(); // happens in the background
this.scheduleKeyBackupSend();
}
// if this.backupInfo is not set, then the keys will be backed up when
// client.enableKeyBackup is called
}; };
/** /**