aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-03-09 18:02:13 +0100
committerAlex Auvolat <alex@adnab.me>2020-03-09 18:02:13 +0100
commit7c39436eda59efb033d172dfa03af3782f0acacf (patch)
tree907549515b8dc61dd55fa728a8620b3c92fd8c0a /external
parentf9e0c58f3c0e90b987b7763f020ea5dcbf366779 (diff)
downloadeasybridge-7c39436eda59efb033d172dfa03af3782f0acacf.tar.gz
easybridge-7c39436eda59efb033d172dfa03af3782f0acacf.zip
Save client pickle automatically (messenger)
Diffstat (limited to 'external')
-rwxr-xr-xexternal/messenger.py13
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)