diff --git a/storage.py b/storage.py index f1c5468..0ca4523 100644 --- a/storage.py +++ b/storage.py @@ -4,21 +4,22 @@ Shamelessly inspired from Syndace's python-omemo examples. """ -import omemo import os import copy import json -from typing import Any, Dict, Set, Union +from typing import Any, Dict, List, Set, Union + +import omemo class SyncFileStorage(omemo.Storage): def __init__(self, storage_dir: str) -> None: self.storage_dir = storage_dir self.__state = None - self.__own_data = None # type: Union[None, Dict[str, str]] + self.__own_data = None # type: Union[None, Dict[str, Union[str, int]]] self.__sessions = {} # type: Dict[str, Dict[int, Any]] - self.__devices = {} # type: Dict[str, Dict[str, Set[int]]] + self.__devices = {} # type: Dict[str, Dict[str, List[int]]] def dump(self): return copy.deepcopy({ @@ -72,8 +73,8 @@ class SyncFileStorage(omemo.Storage): self.__sessions[bare_jid] = self.__sessions.get(bare_jid, {}) self.__sessions[bare_jid][device_id] = session - def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, Set[int]]: - if self.__devices is None: + def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]: + if not self.__devices: try: filepath = os.path.join(self.storage_dir, 'devices.json') with open(filepath, 'r') as f: @@ -91,8 +92,8 @@ class SyncFileStorage(omemo.Storage): with open(filepath, 'w') as f: json.dump(self.__devices, f) - def loadInactiveDevices(self, _callback, bare_jid: str) -> Union[None, Set[int]]: - if self.__devices is None: + def loadInactiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]: + if not self.__devices: try: filepath = os.path.join(self.storage_dir, 'devices.json') with open(filepath, 'r') as f: