mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
stop key backup when on the wrong version
users can then enter the new key in the settings to start backing up again
This commit is contained in:
parent
0b4954a9ca
commit
6f1484005b
@ -646,7 +646,12 @@ export class Session {
|
|||||||
const operation = this._keyBackup.flush(log);
|
const operation = this._keyBackup.flush(log);
|
||||||
this._keyBackupOperation.set(operation);
|
this._keyBackupOperation.set(operation);
|
||||||
try {
|
try {
|
||||||
await operation.result;
|
const success = await operation.result;
|
||||||
|
// stop key backup if the version was changed
|
||||||
|
if (!success) {
|
||||||
|
this._keyBackup = this._keyBackup.dispose();
|
||||||
|
this.needsKeyBackup.set(true);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.catch(err);
|
log.catch(err);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ export class KeyBackup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: protect against having multiple concurrent flushes
|
// TODO: protect against having multiple concurrent flushes
|
||||||
flush(log: ILogItem): AbortableOperation<Promise<void>, Progress> {
|
flush(log: ILogItem): AbortableOperation<Promise<boolean>, Progress> {
|
||||||
return new AbortableOperation(async (setAbortable, setProgress) => {
|
return new AbortableOperation(async (setAbortable, setProgress) => {
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let amountFinished = 0;
|
let amountFinished = 0;
|
||||||
@ -87,7 +87,7 @@ export class KeyBackup {
|
|||||||
setProgress(new Progress(total, amountFinished));
|
setProgress(new Progress(total, amountFinished));
|
||||||
const keysNeedingBackup = await txn.sessionsNeedingBackup.getFirstEntries(20);
|
const keysNeedingBackup = await txn.sessionsNeedingBackup.getFirstEntries(20);
|
||||||
if (keysNeedingBackup.length === 0) {
|
if (keysNeedingBackup.length === 0) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
const roomKeysOrNotFound = await Promise.all(keysNeedingBackup.map(k => keyFromStorage(k.roomId, k.senderKey, k.sessionId, txn)));
|
const roomKeysOrNotFound = await Promise.all(keysNeedingBackup.map(k => keyFromStorage(k.roomId, k.senderKey, k.sessionId, txn)));
|
||||||
const roomKeys = roomKeysOrNotFound.filter(k => !!k) as RoomKey[];
|
const roomKeys = roomKeysOrNotFound.filter(k => !!k) as RoomKey[];
|
||||||
@ -95,7 +95,16 @@ export class KeyBackup {
|
|||||||
const payload = await this.encodeKeysForBackup(roomKeys);
|
const payload = await this.encodeKeysForBackup(roomKeys);
|
||||||
const uploadRequest = this.hsApi.uploadRoomKeysToBackup(this.backupInfo.version, payload, {log});
|
const uploadRequest = this.hsApi.uploadRoomKeysToBackup(this.backupInfo.version, payload, {log});
|
||||||
setAbortable(uploadRequest);
|
setAbortable(uploadRequest);
|
||||||
|
try {
|
||||||
await uploadRequest.response();
|
await uploadRequest.response();
|
||||||
|
} catch (err) {
|
||||||
|
if (err.name === "HomeServerError" && err.errcode === "M_WRONG_ROOM_KEYS_VERSION") {
|
||||||
|
log.set("wrong_version", true);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.removeBackedUpKeys(keysNeedingBackup, setAbortable);
|
this.removeBackedUpKeys(keysNeedingBackup, setAbortable);
|
||||||
amountFinished += keysNeedingBackup.length;
|
amountFinished += keysNeedingBackup.length;
|
||||||
|
Loading…
Reference in New Issue
Block a user