diff options
author | Alex Auvolat <alex@adnab.me> | 2020-03-01 14:48:42 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-03-01 14:48:42 +0100 |
commit | 2eda975741de12ca6340035b27ae3c83ce28c8ec (patch) | |
tree | edbc085c2cf92a7183c2295c0679f56e7a769da1 /external | |
parent | 75a1dee061180f55c8f09db716acf54b1d8e8f9b (diff) | |
download | easybridge-2eda975741de12ca6340035b27ae3c83ce28c8ec.tar.gz easybridge-2eda975741de12ca6340035b27ae3c83ce28c8ec.zip |
Attachments can be received
Diffstat (limited to 'external')
-rwxr-xr-x | external/messenger.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/external/messenger.py b/external/messenger.py index 6b954d4..e9aa4bd 100755 --- a/external/messenger.py +++ b/external/messenger.py @@ -87,7 +87,7 @@ class InitialSyncThread(threading.Thread): self.threads = threads def run(self): - sys.stderr.write("fb thread list: {}\n".format(threads)) + sys.stderr.write("fb thread list: {}\n".format(self.threads)) for thread in self.threads: sys.stderr.write("fb thread: {}\n".format(thread)) @@ -194,9 +194,9 @@ class MessengerBridge: } if user.photo is not None: user_info["avatar"] = mediaObjectOfURL(user.photo) - self.bridge.write({ + self.write({ "_type": USER_INFO_UPDATED, - "user": self.bridge.getUserId(user), + "user": self.getUserId(user), "data": user_info, }) @@ -353,7 +353,7 @@ class MessengerBridge: def ensureJoined(self, userId, room): key = "{}--{}".format(userId, room) if not key in self.joined_map: - self.bridge.write({ + self.write({ "_type": EVENT, "data": { "type": EVENT_JOIN, @@ -368,13 +368,35 @@ class MessengerBridge: # Ignore our own messages return + sys.stderr.write("(python messenger) Got message: {}\n".format(message_object)) + author = self.getUserIdFromUid(message_object.author) event = { "type": EVENT_MESSAGE, "author": author, "text": message_object.text, + "attachments": [] } + for at in message_object.attachments: + if isinstance(at, ImageAttachment): + full_url = self.client.fetchImageUrl(at.uid) + event["attachments"].append({ + "filename": full_url.split("?")[0].split("/")[-1], + "url": full_url, + "image_size": { + "width": at.width, + "height": at.height, + }, + }) + elif isinstance(at, FileAttachment) or isinstance(at, AudioAttachment): + event["attachments"].append({ + "filename": at.url.split("?")[0].split("/")[-1], + "url": at.url, + }) + else: + event["text"] += "\nUnhandled attachment: {}".format(at) + if thread_type == ThreadType.GROUP: event["room"] = thread_id self.ensureJoined(author, thread_id) |