Add detecting replied messages while listening
This commit is contained in:
@@ -3040,6 +3040,24 @@ class Client(object):
|
|||||||
msg=m,
|
msg=m,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
elif d.get("deltaMessageReply"):
|
||||||
|
i = d["deltaMessageReply"]
|
||||||
|
metadata = i["message"]["messageMetadata"]
|
||||||
|
thread_id, thread_type = getThreadIdAndThreadType(metadata)
|
||||||
|
message = graphql_to_message_reply(i["message"])
|
||||||
|
message.replied_to = graphql_to_message_reply(i["repliedToMessage"])
|
||||||
|
self.onMessage(
|
||||||
|
mid=message.uid,
|
||||||
|
author_id=message.author,
|
||||||
|
message=message.text,
|
||||||
|
message_object=message,
|
||||||
|
thread_id=thread_id,
|
||||||
|
thread_type=thread_type,
|
||||||
|
ts=message.timestamp,
|
||||||
|
metadata=metadata,
|
||||||
|
msg=m,
|
||||||
|
)
|
||||||
|
|
||||||
# New message
|
# New message
|
||||||
elif delta.get("class") == "NewMessage":
|
elif delta.get("class") == "NewMessage":
|
||||||
mentions = []
|
mentions = []
|
||||||
|
@@ -406,6 +406,48 @@ def graphql_to_message(message):
|
|||||||
return rtn
|
return rtn
|
||||||
|
|
||||||
|
|
||||||
|
def graphql_to_message_reply(message):
|
||||||
|
rtn = Message(
|
||||||
|
text=message.get("body"),
|
||||||
|
mentions=[
|
||||||
|
Mention(m.get("i"), offset=m.get("o"), length=m.get("l"))
|
||||||
|
for m in json.loads(message.get("data", {}).get("prng", "[]"))
|
||||||
|
],
|
||||||
|
emoji_size=get_emojisize_from_tags(message["messageMetadata"].get("tags")),
|
||||||
|
)
|
||||||
|
metadata = message.get("messageMetadata", {})
|
||||||
|
rtn.uid = metadata.get("messageId")
|
||||||
|
rtn.author = str(metadata.get("actorFbId"))
|
||||||
|
rtn.timestamp = metadata.get("timestamp")
|
||||||
|
rtn.unsent = False
|
||||||
|
if message.get("data", {}).get("platform_xmd"):
|
||||||
|
quick_replies = json.loads(message["data"]["platform_xmd"]).get("quick_replies")
|
||||||
|
if isinstance(quick_replies, list):
|
||||||
|
rtn.quick_replies = [graphql_to_quick_reply(q) for q in quick_replies]
|
||||||
|
elif isinstance(quick_replies, dict):
|
||||||
|
rtn.quick_replies = [
|
||||||
|
graphql_to_quick_reply(quick_replies, is_response=True)
|
||||||
|
]
|
||||||
|
if message.get("attachments") is not None:
|
||||||
|
for attachment in message["attachments"]:
|
||||||
|
attachment = json.loads(attachment["mercuryJSON"])
|
||||||
|
if attachment.get("blob_attachment"):
|
||||||
|
rtn.attachments.append(
|
||||||
|
graphql_to_attachment(attachment["blob_attachment"])
|
||||||
|
)
|
||||||
|
if attachment.get("extensible_attachment"):
|
||||||
|
extensible_attachment = graphql_to_extensible_attachment(
|
||||||
|
attachment["extensible_attachment"]
|
||||||
|
)
|
||||||
|
if isinstance(extensible_attachment, UnsentMessage):
|
||||||
|
rtn.unsent = True
|
||||||
|
else:
|
||||||
|
rtn.attachments.append(extensible_attachment)
|
||||||
|
if attachment.get("sticker_attachment"):
|
||||||
|
rtn.sticker = graphql_to_sticker(attachment["sticker_attachment"])
|
||||||
|
return rtn
|
||||||
|
|
||||||
|
|
||||||
def graphql_to_user(user):
|
def graphql_to_user(user):
|
||||||
if user.get("profile_picture") is None:
|
if user.get("profile_picture") is None:
|
||||||
user["profile_picture"] = {}
|
user["profile_picture"] = {}
|
||||||
|
@@ -20,6 +20,7 @@ from ._graphql import (
|
|||||||
graphql_to_plan,
|
graphql_to_plan,
|
||||||
graphql_to_quick_reply,
|
graphql_to_quick_reply,
|
||||||
graphql_to_message,
|
graphql_to_message,
|
||||||
|
graphql_to_message_reply,
|
||||||
graphql_to_user,
|
graphql_to_user,
|
||||||
graphql_to_thread,
|
graphql_to_thread,
|
||||||
graphql_to_group,
|
graphql_to_group,
|
||||||
|
Reference in New Issue
Block a user