aboutsummaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
Diffstat (limited to 'external')
-rwxr-xr-xexternal/messenger.py30
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)