Attachments can be received

This commit is contained in:
Alex 2020-03-01 14:48:42 +01:00
parent 75a1dee061
commit 2eda975741
1 changed files with 26 additions and 4 deletions

30
external/messenger.py vendored
View File

@ -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)