From f251d67c32e001a01c19faac800762ba146c2339 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sun, 1 Mar 2020 15:38:54 +0100 Subject: UNTESTED: GROUP CHATS ;; add handlers for member join/leave and name changes --- external/messenger.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'external') diff --git a/external/messenger.py b/external/messenger.py index cd5d972..f857b46 100755 --- a/external/messenger.py +++ b/external/messenger.py @@ -389,7 +389,7 @@ class MessengerBridge: "room": room, } }) - self.joined_map[key] = true + self.joined_map[key] = True def onMessage(self, thread_id, thread_type, message_object, **kwargs): if message_object.author == self.client.uid: @@ -443,12 +443,29 @@ class MessengerBridge: self.cache_put("last_seen_%s"%thread_id, message_object.uid) - def onPeopleAdded(self, *args, **kwargs): - pass - def onPersonRemoved(self, *args, **kwargs): - pass - def onTitleChange(self, *args, **kwargs): - pass + def onPeopleAdded(self, added_ids, thread_id, *args, **kwargs): + for user_id in added_ids: + self.ensureJoined(self.getUserIdFromUid(user_id), thread_id) + + def onPersonRemoved(self, removed_id, thread_id, *args, **kwargs): + userId = self.getUserIdFromUid(removed_id), + self.write({ + "_type": EVENT, + "data": { + "type": EVENT_JOIN, + "author": userId, + "room": thread_id, + } + }) + del self.joined_map["{}--{}".format(userId, thread_id)] + + def onTitleChange(self, author_id, new_title, thread_id, thread_type, *args, **kwargs): + if thread_type == ThreadType.GROUP: + self.bridge.write({ + "_type": ROOM_INFO_UPDATED, + "room": thread_id, + "data": {"name": new_title}, + }) if __name__ == "__main__": bridge = MessengerBridge() -- cgit v1.2.3