From 2eda975741de12ca6340035b27ae3c83ce28c8ec Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 1 Mar 2020 14:48:42 +0100 Subject: Attachments can be received --- external/messenger.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'external') 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) -- cgit v1.2.3