From 2b288bdfc62b0046f799f8c19d5376eecc67f4fa Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 23 Nov 2019 11:14:14 -0400 Subject: [PATCH] Import/export keys improvements --- src/python/matrix_client.py | 35 +------------------ src/qml/Dialogs/ImportKeys.qml | 11 +++++- .../Pages/AccountSettings/AccountSettings.qml | 2 +- src/qml/Pages/AccountSettings/Encryption.qml | 23 ------------ 4 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 src/qml/Pages/AccountSettings/Encryption.qml diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index 91a473cb..1afb685e 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -7,7 +7,6 @@ import re import traceback from contextlib import suppress from datetime import datetime -from functools import partial from pathlib import Path from typing import ( Any, DefaultDict, Dict, NamedTuple, Optional, Set, Tuple, Type, Union, @@ -606,35 +605,7 @@ class MatrixClient(nio.AsyncClient): async def import_keys(self, infile: str, passphrase: str) -> None: - # Reimplemented until better solutions are worked on in nio - await self.clear_import_error() - - loop = asyncio.get_event_loop() - - account = self.models[Account][self.user_id] - import_keys = partial(self.olm.import_keys_static, infile, passphrase) - - account.importing_key = 0 - account.total_keys_to_import = -1 # preparing - - try: - sessions = await loop.run_in_executor(None, import_keys) - except nio.EncryptionError as err: # XXX raise - account.import_error = (infile, passphrase, str(err)) - return - - account.total_keys_to_import = len(sessions) - - for session in sessions: - if self.olm.inbound_group_store.add(session): - await loop.run_in_executor( - None, self.store.save_inbound_group_session, session, - ) - account.importing_key += 1 - - account.importing_key = 0 - account.total_keys_to_import = 0 - + await super().import_keys(infile, passphrase) await self.retry_decrypting_events() @@ -649,10 +620,6 @@ class MatrixClient(nio.AsyncClient): await super().export_keys(outfile, passphrase) - async def clear_import_error(self) -> None: - self.models[Account][self.user_id].import_error = ("", "", "") - - async def retry_decrypting_events(self) -> None: for sync_id, model in self.models.items(): if not (isinstance(sync_id, tuple) and diff --git a/src/qml/Dialogs/ImportKeys.qml b/src/qml/Dialogs/ImportKeys.qml index 04553402..cd08f3b8 100644 --- a/src/qml/Dialogs/ImportKeys.qml +++ b/src/qml/Dialogs/ImportKeys.qml @@ -11,12 +11,21 @@ HFileDialogOpener { } + signal done() + + property string userId: "" + property bool importing: false function importKeys(file, passphrase) { + importing = true + let path = file.toString().replace(/^file:\/\//, "") - py.callClientCoro(userId, "import_keys", [path, passphrase]) + py.callClientCoro(userId, "import_keys", [path, passphrase], () => { + importing = false + done() + }) } diff --git a/src/qml/Pages/AccountSettings/AccountSettings.qml b/src/qml/Pages/AccountSettings/AccountSettings.qml index ea732343..02ecc09a 100644 --- a/src/qml/Pages/AccountSettings/AccountSettings.qml +++ b/src/qml/Pages/AccountSettings/AccountSettings.qml @@ -30,7 +30,7 @@ HPage { Repeater { id: repeater - model: ["Profile.qml", "Encryption.qml"] + model: ["Profile.qml", "ImportExportKeys.qml"] Rectangle { color: ready ? theme.controls.box.background : "transparent" diff --git a/src/qml/Pages/AccountSettings/Encryption.qml b/src/qml/Pages/AccountSettings/Encryption.qml deleted file mode 100644 index 11b02b8e..00000000 --- a/src/qml/Pages/AccountSettings/Encryption.qml +++ /dev/null @@ -1,23 +0,0 @@ -import QtQuick 2.12 -import "../../Base" - -HLoader { - id: encryptionUI - source: - accountInfo.import_error[0] ? "ImportError.qml" : - accountInfo.total_keys_to_import ? "ImportingKeys.qml" : - "ImportExportKeys.qml" - - onSourceChanged: animation.running = true - - - SequentialAnimation { - id: animation - HNumberAnimation { - target: encryptionUI; property: "scale"; to: 0; - } - HNumberAnimation { - target: encryptionUI; property: "scale"; to: 1; overshoot: 3; - } - } -}