From eb0759caf5ecfb511438aa9aa3924632284772f3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 31 Jul 2023 17:18:52 +0200 Subject: [PATCH 1/2] fix: fix upload of old session after reset Otherwise we would need to wait for a new inbound session to upload them. It might increase disk usage a bit every 10 minutes. --- lib/encryption/key_manager.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 2aefd18d..435d1667 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -182,8 +182,6 @@ class KeyManager { if (uploaded) { await client.database ?.markInboundGroupSessionAsUploaded(roomId, sessionId); - } else { - _haveKeysToUpload = true; } }); final room = client.getRoomById(roomId); @@ -750,7 +748,6 @@ class KeyManager { } bool _isUploadingKeys = false; - bool _haveKeysToUpload = true; Future backgroundTasks() async { final database = client.database; @@ -760,12 +757,11 @@ class KeyManager { } _isUploadingKeys = true; try { - if (!_haveKeysToUpload || !(await isCached())) { + if (!(await isCached())) { return; // we can't backup anyways } final dbSessions = await database.getInboundGroupSessionsToUpload(); if (dbSessions.isEmpty) { - _haveKeysToUpload = false; return; // nothing to do } final privateKey = From a016709a4088f913703d61afe17aac2545e648f8 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 31 Jul 2023 17:25:28 +0200 Subject: [PATCH 2/2] feat: Upload keys on OKB reset This does make the reset take longer on big accounts, but otherwise users might sign out before the keys are uploaded, which makes the reset more destructive than necessary. In the common case of not having any keys it shouldn't make a difference. --- lib/encryption/utils/bootstrap.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/encryption/utils/bootstrap.dart b/lib/encryption/utils/bootstrap.dart index dc728b63..184d14f1 100644 --- a/lib/encryption/utils/bootstrap.dart +++ b/lib/encryption/utils/bootstrap.dart @@ -584,6 +584,8 @@ class Bootstrap { Logs().v( 'And finally set all megolm keys as needing to be uploaded again...'); await client.database?.markInboundGroupSessionsAsNeedingUpload(); + Logs().v('And uploading keys...'); + await client.encryption?.keyManager.backgroundTasks(); } catch (e, s) { Logs().e('[Bootstrapping] Error setting up online key backup', e, s); state = BootstrapState.error;