Skip to content

Commit

Permalink
Add a function to flag keys for backup without scheduling a backup
Browse files Browse the repository at this point in the history
For element-hq/element-web#10263

Starting/scheduling the backup won't help us because the token would be invalid from a server perspective. Instead, we should update what needs to be done and return a count.
  • Loading branch information
turt2live committed Jul 5, 2019
1 parent 60e339b commit 3a0f27f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,19 @@ MatrixClient.prototype.scheduleAllGroupSessionsForBackup = async function() {
await this._crypto.scheduleAllGroupSessionsForBackup();
};

/**
* Marks all group sessions as needing to be backed up without scheduling
* them to upload in the background.
* @returns {Promise<int>} Resolves to the number of sessions requiring a backup.
*/
MatrixClient.prototype.flagAllGroupSessionsForBackup = function() {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}

return this._crypto.flagAllGroupSessionsForBackup();
};

MatrixClient.prototype.isValidRecoveryKey = function(recoveryKey) {
try {
decodeRecoveryKey(recoveryKey);
Expand Down
16 changes: 13 additions & 3 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,18 @@ Crypto.prototype.backupGroupSession = async function(
* upload in the background as soon as possible.
*/
Crypto.prototype.scheduleAllGroupSessionsForBackup = async function() {
await this.flagAllGroupSessionsForBackup();

// Schedule keys to upload in the background as soon as possible.
this.scheduleKeyBackupSend(0 /* maxDelay */);
};

/**
* Marks all group sessions as needing to be backed up without scheduling
* them to upload in the background.
* @returns {Promise<int>} Resolves to the number of sessions requiring a backup.
*/
Crypto.prototype.flagAllGroupSessionsForBackup = async function() {
await this._cryptoStore.doTxn(
'readwrite',
[
Expand All @@ -1305,9 +1317,7 @@ Crypto.prototype.scheduleAllGroupSessionsForBackup = async function() {

const remaining = await this._cryptoStore.countSessionsNeedingBackup();
this.emit("crypto.keyBackupSessionsRemaining", remaining);

// Schedule keys to upload in the background as soon as possible.
this.scheduleKeyBackupSend(0 /* maxDelay */);
return remaining;
};

/* eslint-disable valid-jsdoc */ //https://github.com/eslint/eslint/issues/7307
Expand Down

0 comments on commit 3a0f27f

Please sign in to comment.