diff options
Diffstat (limited to 'external')
-rwxr-xr-x | external/messenger.py | 13 |
1 files changed, 10 insertions, 3 deletions
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) |