Show import keys error in the UI

This commit is contained in:
miruka
2019-08-28 11:42:52 -04:00
parent 7d2cbae26f
commit ce3404a516
8 changed files with 84 additions and 35 deletions

View File

@@ -304,17 +304,21 @@ class MatrixClient(nio.AsyncClient):
return True
async def import_keys(self, infile: str, passphrase: str) -> Optional[str]:
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)
try:
sessions = await loop.run_in_executor(None, import_keys)
except nio.EncryptionError as err:
return str(err)
account.import_error = (infile, passphrase, str(err))
return
account = self.models[Account][self.user_id]
account.importing_key = 0
account.total_keys_to_import = len(sessions)
@@ -330,6 +334,10 @@ class MatrixClient(nio.AsyncClient):
return None
async def clear_import_error(self) -> None:
self.models[Account][self.user_id].import_error = ("", "", "")
# Functions to register data into models
async def event_is_past(self, ev: Union[nio.Event, Event]) -> bool:

View File

@@ -1,7 +1,7 @@
import re
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Tuple
from ..html_filter import HTML_FILTER
from ..utils import AutoStrEnum, auto
@@ -16,8 +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
importing_key: int = 0
total_keys_to_import: int = 0
import_error: Tuple[str, str, str] = ("", "", "") # path,pw,err
def __lt__(self, other: "Account") -> bool:
name = self.display_name or self.user_id[1:]