Attachments can be received

This commit is contained in:
Alex 2020-03-01 14:48:42 +01:00
parent 75a1dee061
commit 2eda975741

30
external/messenger.py vendored
View file

@ -87,7 +87,7 @@ class InitialSyncThread(threading.Thread):
self.threads = threads self.threads = threads
def run(self): 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: for thread in self.threads:
sys.stderr.write("fb thread: {}\n".format(thread)) sys.stderr.write("fb thread: {}\n".format(thread))
@ -194,9 +194,9 @@ class MessengerBridge:
} }
if user.photo is not None: if user.photo is not None:
user_info["avatar"] = mediaObjectOfURL(user.photo) user_info["avatar"] = mediaObjectOfURL(user.photo)
self.bridge.write({ self.write({
"_type": USER_INFO_UPDATED, "_type": USER_INFO_UPDATED,
"user": self.bridge.getUserId(user), "user": self.getUserId(user),
"data": user_info, "data": user_info,
}) })
@ -353,7 +353,7 @@ class MessengerBridge:
def ensureJoined(self, userId, room): def ensureJoined(self, userId, room):
key = "{}--{}".format(userId, room) key = "{}--{}".format(userId, room)
if not key in self.joined_map: if not key in self.joined_map:
self.bridge.write({ self.write({
"_type": EVENT, "_type": EVENT,
"data": { "data": {
"type": EVENT_JOIN, "type": EVENT_JOIN,
@ -368,13 +368,35 @@ class MessengerBridge:
# Ignore our own messages # Ignore our own messages
return return
sys.stderr.write("(python messenger) Got message: {}\n".format(message_object))
author = self.getUserIdFromUid(message_object.author) author = self.getUserIdFromUid(message_object.author)
event = { event = {
"type": EVENT_MESSAGE, "type": EVENT_MESSAGE,
"author": author, "author": author,
"text": message_object.text, "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: if thread_type == ThreadType.GROUP:
event["room"] = thread_id event["room"] = thread_id
self.ensureJoined(author, thread_id) self.ensureJoined(author, thread_id)