From 7db7868d2b8f546d6434d2a5ceaa6e6c62f74010 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Wed, 17 Apr 2019 22:34:19 +0200 Subject: [PATCH 1/2] Fix forwarding replied messages (#417) --- fbchat/_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index c72c88d..fa08e3e 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -1061,6 +1061,8 @@ class Client(object): read_receipts = j["message_thread"]["read_receipts"]["nodes"] for message in messages: + if message.replied_to: + message.reply_to_id = message.replied_to.uid for receipt in read_receipts: if int(receipt["watermark"]) >= int(message.timestamp): message.read_by.append(receipt["actor"]["id"]) @@ -1178,7 +1180,10 @@ class Client(object): """ thread_id, thread_type = self._getThread(thread_id, None) message_info = self._forcedFetch(thread_id, mid).get("message") - return graphql_to_message(message_info) + message = graphql_to_message(message_info) + if message.replied_to: + message.reply_to_id = message.replied_to.uid + return message def fetchPollOptions(self, poll_id): """ @@ -2919,6 +2924,7 @@ class Client(object): thread_id, thread_type = getThreadIdAndThreadType(metadata) message = graphql_to_message_reply(i["message"]) message.replied_to = graphql_to_message_reply(i["repliedToMessage"]) + message.reply_to_id = message.replied_to.uid self.onMessage( mid=message.uid, author_id=message.author, From 73c6be1969ff684c648a75715dfb1ff1dfbac40f Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Wed, 17 Apr 2019 22:35:04 +0200 Subject: [PATCH 2/2] Add message parameter to sending location (#416) --- fbchat/_client.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fbchat/_client.py b/fbchat/_client.py index fa08e3e..3c416ab 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -1472,23 +1472,29 @@ class Client(object): r = self._post(self.req_url.UNSEND, data) r.raise_for_status() - def _sendLocation(self, location, current=True, thread_id=None, thread_type=None): + def _sendLocation( + self, location, current=True, message=None, thread_id=None, thread_type=None + ): thread_id, thread_type = self._getThread(thread_id, thread_type) - data = self._getSendData(thread_id=thread_id, thread_type=thread_type) + data = self._getSendData( + message=message, thread_id=thread_id, thread_type=thread_type + ) data["action_type"] = "ma-type:user-generated-message" data["location_attachment[coordinates][latitude]"] = location.latitude data["location_attachment[coordinates][longitude]"] = location.longitude data["location_attachment[is_current_location]"] = current return self._doSendRequest(data) - def sendLocation(self, location, thread_id=None, thread_type=None): + def sendLocation(self, location, message=None, thread_id=None, thread_type=None): """ Sends a given location to a thread as the user's current location :param location: Location to send + :param message: Additional message :param thread_id: User/Group ID to send to. See :ref:`intro_threads` :param thread_type: See :ref:`intro_threads` :type location: models.LocationAttachment + :type message: models.Message :type thread_type: models.ThreadType :return: :ref:`Message ID ` of the sent message :raises: FBchatException if request failed @@ -1496,18 +1502,23 @@ class Client(object): self._sendLocation( location=location, current=True, + message=message, thread_id=thread_id, thread_type=thread_type, ) - def sendPinnedLocation(self, location, thread_id=None, thread_type=None): + def sendPinnedLocation( + self, location, message=None, thread_id=None, thread_type=None + ): """ Sends a given location to a thread as a pinned location :param location: Location to send + :param message: Additional message :param thread_id: User/Group ID to send to. See :ref:`intro_threads` :param thread_type: See :ref:`intro_threads` :type location: models.LocationAttachment + :type message: models.Message :type thread_type: models.ThreadType :return: :ref:`Message ID ` of the sent message :raises: FBchatException if request failed @@ -1515,6 +1526,7 @@ class Client(object): self._sendLocation( location=location, current=False, + message=message, thread_id=thread_id, thread_type=thread_type, )