From 7c39436eda59efb033d172dfa03af3782f0acacf Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 9 Mar 2020 18:02:13 +0100 Subject: Save client pickle automatically (messenger) --- external/messenger.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'external') diff --git a/external/messenger.py b/external/messenger.py index 6da4808..e45a45e 100755 --- a/external/messenger.py +++ b/external/messenger.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -# @FIXME: store the client pickle in the config automatically - import sys import json import signal @@ -34,6 +32,7 @@ SEND = "send" CLOSE = "close" # external -> ezbr +SAVE_CONFIG = "save_config" JOINED = "joined" LEFT = "left" USER_INFO_UPDATED = "user_info_updated" @@ -228,7 +227,8 @@ class MessengerBridge: if ty == CONFIGURE: self.init_backlog_length = int(cmd["data"]["initial_backlog"]) - if "client_pickle" in cmd["data"] and len(cmd["data"]["client_pickle"]) > 0: + has_pickle = "client_pickle" in cmd["data"] and len(cmd["data"]["client_pickle"]) > 0 + if has_pickle: data = base64.b64decode(cmd["data"]["client_pickle"]) data = zlib.decompress(data) self.client = pickle.loads(data) @@ -240,6 +240,13 @@ class MessengerBridge: if not self.client.isLoggedIn(): return {"_type": REP_ERROR, "error": "Unable to login (invalid pickle?)"} + if not has_pickle: + new_config = cmd["data"] + data = pickle.dumps(self.client) + data = zlib.compress(data) + new_config["client_pickle"] = base64.b64encode(data).decode('ascii') + self.write({"_type": SAVE_CONFIG, "data": new_config}) + self.client.setBridge(self) self.my_user_id = self.getUserIdFromUid(self.client.uid) -- cgit v1.2.3