From 05ef6d75c3c37f665f3e699f9afcae6a55edfcdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 1 Dec 2018 18:22:34 +0000 Subject: [PATCH] xep_0384: store sessions to file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- storage.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/storage.py b/storage.py index 0ca4523..3ebcebd 100644 --- a/storage.py +++ b/storage.py @@ -67,12 +67,24 @@ class SyncFileStorage(omemo.Storage): json.dump(self.__state, f) def loadSession(self, _callback, bare_jid: str, device_id: int): + if not self.__sessions: + try: + filepath = os.path.join(self.storage_dir, 'sessions.json') + with open(filepath, 'r') as f: + self.__sessions = json.load(f) + except OSError: + return None + return self.__sessions.get(bare_jid, {}).get(device_id, None) def storeSession(self, callback, bare_jid: str, device_id: int, session) -> None: self.__sessions[bare_jid] = self.__sessions.get(bare_jid, {}) self.__sessions[bare_jid][device_id] = session + filepath = os.path.join(self.storage_dir, 'sessions.json') + with open(filepath, 'w') as f: + json.dump(self.__sessions, f) + def loadActiveDevices(self, _callback, bare_jid: str) -> Union[None, List[int]]: if not self.__devices: try: