Show key import progression

This commit is contained in:
miruka
2019-08-28 03:54:53 -04:00
parent f65c0176ba
commit 7d2cbae26f
5 changed files with 158 additions and 74 deletions

View File

@@ -7,6 +7,7 @@ import platform
from contextlib import suppress
from datetime import datetime
from enum import Enum
from functools import partial
from pathlib import Path
from types import ModuleType
from typing import DefaultDict, Dict, Optional, Set, Tuple, Type, Union
@@ -303,6 +304,32 @@ class MatrixClient(nio.AsyncClient):
return True
async def import_keys(self, infile: str, passphrase: str) -> Optional[str]:
# Reimplemented until better solutions are worked on in nio
loop = asyncio.get_event_loop()
import_keys = partial(self.olm.import_keys_static, infile, passphrase)
try:
sessions = await loop.run_in_executor(None, import_keys)
except nio.EncryptionError as err:
return str(err)
account = self.models[Account][self.user_id]
account.importing_key = 0
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
return None
# Functions to register data into models
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:

View File

@@ -16,6 +16,9 @@ class Account(ModelItem):
first_sync_done: bool = False
profile_updated: Optional[datetime] = None
importing_key: int = 0
total_keys_to_import: int = 0
def __lt__(self, other: "Account") -> bool:
name = self.display_name or self.user_id[1:]
other_name = other.display_name or other.user_id[1:]