Skip to content

Commit 3a0f27f

Browse files
committed
Add a function to flag keys for backup without scheduling a backup
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.
1 parent 60e339b commit 3a0f27f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/client.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,19 @@ MatrixClient.prototype.scheduleAllGroupSessionsForBackup = async function() {
12081208
await this._crypto.scheduleAllGroupSessionsForBackup();
12091209
};
12101210

1211+
/**
1212+
* Marks all group sessions as needing to be backed up without scheduling
1213+
* them to upload in the background.
1214+
* @returns {Promise<int>} Resolves to the number of sessions requiring a backup.
1215+
*/
1216+
MatrixClient.prototype.flagAllGroupSessionsForBackup = function() {
1217+
if (this._crypto === null) {
1218+
throw new Error("End-to-end encryption disabled");
1219+
}
1220+
1221+
return this._crypto.flagAllGroupSessionsForBackup();
1222+
};
1223+
12111224
MatrixClient.prototype.isValidRecoveryKey = function(recoveryKey) {
12121225
try {
12131226
decodeRecoveryKey(recoveryKey);

src/crypto/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,18 @@ Crypto.prototype.backupGroupSession = async function(
12881288
* upload in the background as soon as possible.
12891289
*/
12901290
Crypto.prototype.scheduleAllGroupSessionsForBackup = async function() {
1291+
await this.flagAllGroupSessionsForBackup();
1292+
1293+
// Schedule keys to upload in the background as soon as possible.
1294+
this.scheduleKeyBackupSend(0 /* maxDelay */);
1295+
};
1296+
1297+
/**
1298+
* Marks all group sessions as needing to be backed up without scheduling
1299+
* them to upload in the background.
1300+
* @returns {Promise<int>} Resolves to the number of sessions requiring a backup.
1301+
*/
1302+
Crypto.prototype.flagAllGroupSessionsForBackup = async function() {
12911303
await this._cryptoStore.doTxn(
12921304
'readwrite',
12931305
[
@@ -1305,9 +1317,7 @@ Crypto.prototype.scheduleAllGroupSessionsForBackup = async function() {
13051317

13061318
const remaining = await this._cryptoStore.countSessionsNeedingBackup();
13071319
this.emit("crypto.keyBackupSessionsRemaining", remaining);
1308-
1309-
// Schedule keys to upload in the background as soon as possible.
1310-
this.scheduleKeyBackupSend(0 /* maxDelay */);
1320+
return remaining;
13111321
};
13121322

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

0 commit comments

Comments
 (0)