From 83789dcefa26c3fe4423ca6d105b208185b7d0e5 Mon Sep 17 00:00:00 2001 From: cirrux Date: Tue, 26 Dec 2017 19:12:10 -0500 Subject: [PATCH 1/4] Fix attachment parsing for newer structure --- fbchat/client.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 4161fea..c45252e 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1482,21 +1482,20 @@ class Client(object): try: for a in delta['attachments']: mercury = a['mercury'] - if mercury.get('attach_type'): + if mercury.get('blob_attachment'): image_metadata = a.get('imageMetadata', {}) - attach_type = mercury['attach_type'] - if attach_type != 'share': - attachment = graphql_to_attachment(mercury.get('blob_attachment', {})) - else: - # TODO: Add more data here for shared stuff (URLs, events and so on) - pass + attach_type = mercury['blob_attachment']['__typename'] + attachment = graphql_to_attachment(mercury.get('blob_attachment', {})) - if attach_type == ['file', 'video']: + if attach_type == ['MessageFile', 'MessageVideo', 'MessageAudio']: # TODO: Add more data here for audio files attachment.size = int(a['fileSize']) attachments.append(attachment) - if a['mercury'].get('sticker_attachment'): + elif mercury.get('sticker_attachment'): sticker = graphql_to_sticker(a['mercury']['sticker_attachment']) + elif mercury.get('extensible_attachment'): + # TODO: Add more data here for shared stuff (URLs, events and so on) + pass except Exception: log.exception('An exception occured while reading attachments: {}'.format(delta['attachments'])) From a946050228cb903265793664c1b78cdc103eebc9 Mon Sep 17 00:00:00 2001 From: cirrux Date: Sun, 31 Dec 2017 12:27:55 -0500 Subject: [PATCH 2/4] Re-enable typing notification --- fbchat/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index c45252e..ab09c70 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1526,10 +1526,10 @@ class Client(object): self.onInbox(unseen=m["unseen"], unread=m["unread"], recent_unread=m["recent_unread"], msg=m) # Typing - # elif mtype == "typ": - # author_id = str(m.get("from")) - # typing_status = TypingStatus(m.get("st")) - # self.onTyping(author_id=author_id, typing_status=typing_status) + elif mtype == "typ": + author_id = str(m.get("from")) + typing_status = TypingStatus(m.get("st")) + self.onTyping(author_id=author_id, typing_status=typing_status) # Delivered From c495317e6520f159c1137aa5fda25a9ac3b93c83 Mon Sep 17 00:00:00 2001 From: cirrux Date: Mon, 1 Jan 2018 23:11:35 -0500 Subject: [PATCH 3/4] Fix setTypingStatus to send correctly --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index ab09c70..91a8018 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1248,7 +1248,7 @@ class Client(object): :type thread_type: models.ThreadType :raises: FBchatException if request failed """ - thread_id, thread_type = self._getThread(thread_id, None) + thread_id, thread_type = self._getThread(thread_id, thread_type) data = { "typ": status.value, From bbc34bd009646983bf1d1bff387e5ff610f15699 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 2 Jan 2018 13:33:13 +0100 Subject: [PATCH 4/4] Added onTyping method --- fbchat/client.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 91a8018..8754d33 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1528,8 +1528,13 @@ class Client(object): # Typing elif mtype == "typ": author_id = str(m.get("from")) + thread_id = str(m.get("to")) + if thread_id == self.uid: + thread_type = ThreadType.USER + else: + thread_type = ThreadType.GROUP typing_status = TypingStatus(m.get("st")) - self.onTyping(author_id=author_id, typing_status=typing_status) + self.onTyping(author_id=author_id, status=typing_status, thread_id=thread_id, thread_type=thread_type, msg=m) # Delivered @@ -1849,6 +1854,20 @@ class Client(object): """ log.info('Inbox event: {}, {}, {}'.format(unseen, unread, recent_unread)) + def onTyping(self, author_id=None, status=None, thread_id=None, thread_type=None, msg=None): + """ + Called when the client is listening, and somebody starts or stops typing into a chat + + :param author_id: The ID of the person who sent the action + :param status: The typing status + :param thread_id: Thread ID that the action was sent to. See :ref:`intro_threads` + :param thread_type: Type of thread that the action was sent to. See :ref:`intro_threads` + :param msg: A full set of the data recieved + :type typing_status: models.TypingStatus + :type thread_type: models.ThreadType + """ + pass + def onQprimer(self, ts=None, msg=None): """ Called when the client just started listening