Skip to content

Commit

Permalink
Pyrofork: Add reply_to_story field to Message
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Sep 22, 2023
1 parent 01ba0ab commit c0c7d37
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class Message(Object, Update):
For replies, the original message. Note that the Message object in this field will not contain
further reply_to_message fields even if it itself is a reply.
reply_to_story (:obj:`~pyrogram.types.Story`, *optional*):
For replies, the original story.
mentioned (``bool``, *optional*):
The message contains a mention.
Expand Down Expand Up @@ -378,6 +381,7 @@ def __init__(
reply_to_story_user_id: int = None,
reply_to_top_message_id: int = None,
reply_to_message: "Message" = None,
reply_to_story: "types.Story" = None,
mentioned: bool = None,
empty: bool = None,
service: "enums.MessageServiceType" = None,
Expand Down Expand Up @@ -470,6 +474,7 @@ def __init__(
self.reply_to_story_user_id = reply_to_story_user_id
self.reply_to_top_message_id = reply_to_top_message_id
self.reply_to_message = reply_to_message
self.reply_to_story = reply_to_story
self.mentioned = mentioned
self.empty = empty
self.service = service
Expand Down Expand Up @@ -1003,20 +1008,31 @@ async def _parse(
parsed_message.reply_to_story_user_id = message.reply_to.user_id

if replies:
try:
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
reply_to_message = client.message_cache[key]

if not reply_to_message:
reply_to_message = await client.get_messages(
parsed_message.chat.id,
reply_to_message_ids=message.id,
replies=replies - 1
if parsed_message.reply_to_message_id:
try:
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
reply_to_message = client.message_cache[key]

if not reply_to_message:
reply_to_message = await client.get_messages(
parsed_message.chat.id,
reply_to_message_ids=message.id,
replies=replies - 1
)
if reply_to_message and not reply_to_message.forum_topic_created:
parsed_message.reply_to_message = reply_to_message
except MessageIdsEmpty:
pass
elif parsed_message.reply_to_story_id:
try:
reply_to_story = await client.get_stories(
parsed_message.reply_to_story_user_id,
parsed_message.reply_to_story_id
)
if reply_to_message and not reply_to_message.forum_topic_created:
parsed_message.reply_to_message = reply_to_message
except MessageIdsEmpty:
pass
except Exception:
pass
else:
parsed_message.reply_to_story = reply_to_story

if not parsed_message.poll: # Do not cache poll messages
client.message_cache[(parsed_message.chat.id, parsed_message.id)] = parsed_message
Expand Down

0 comments on commit c0c7d37

Please sign in to comment.