diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index 006a11010..f8ce23a3f 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -369,17 +369,11 @@ MegolmEncryption.prototype._prepareNewSession = async function() { key.key, {ed25519: this._olmDevice.deviceEd25519Key}, ); - if (this._crypto.backupInfo) { - // don't wait for it to complete - this._crypto.backupGroupSession( - this._roomId, this._olmDevice.deviceCurve25519Key, [], - 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); - }); - } + // don't wait for it to complete + this._crypto.backupGroupSession( + this._roomId, this._olmDevice.deviceCurve25519Key, [], + sessionId, key.key, + ); return new OutboundSessionInfo(sessionId); }; @@ -1347,18 +1341,12 @@ MegolmDecryption.prototype.onRoomKeyEvent = function(event) { } }); }).then(() => { - if (this._crypto.backupInfo) { - // don't wait for the keys to be backed up for the server - this._crypto.backupGroupSession( - content.room_id, senderKey, forwardingKeyChain, - content.session_id, content.session_key, keysClaimed, - 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); - }); - } + // don't wait for the keys to be backed up for the server + this._crypto.backupGroupSession( + content.room_id, senderKey, forwardingKeyChain, + content.session_id, content.session_key, keysClaimed, + exportFormat, + ); }).catch((e) => { logger.error(`Error handling m.room_key_event: ${e}`); }); @@ -1564,7 +1552,7 @@ MegolmDecryption.prototype.importRoomKey = function(session, opts = {}) { true, opts.untrusted ? { untrusted: opts.untrusted } : {}, ).then(() => { - if (this._crypto.backupInfo && opts.source !== "backup") { + if (opts.source !== "backup") { // don't wait for it to complete this._crypto.backupGroupSession( session.room_id, diff --git a/src/crypto/index.js b/src/crypto/index.js index 332ff7019..9b4a5bd6e 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -2884,18 +2884,18 @@ Crypto.prototype.backupGroupSession = async function( sessionId, sessionKey, keysClaimed, exportFormat, ) { - if (!this.backupInfo) { - throw new Error("Key backups are not enabled"); - } - await this._cryptoStore.markSessionsNeedingBackup([{ senderKey: senderKey, sessionId: sessionId, }]); - // don't wait for this to complete: it will delay so - // happens in the background - this.scheduleKeyBackupSend(); + if (this.backupInfo) { + // don't wait for this to complete: it will delay so + // happens in the background + this.scheduleKeyBackupSend(); + } + // if this.backupInfo is not set, then the keys will be backed up when + // client.enableKeyBackup is called }; /**