mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Revert "Pyrofork: types: message: Fix cross chat reply parsing"
This reverts commit b4cb8ff17c.
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
e5c8f25a71
commit
00fed09311
2 changed files with 14 additions and 53 deletions
|
|
@ -1273,20 +1273,15 @@ class Message(Object, Update):
|
|||
|
||||
if replies:
|
||||
if parsed_message.reply_to_message_id:
|
||||
if rtci is not None and parsed_message.chat.id != reply_to_chat_id:
|
||||
key = (reply_to_chat_id, message.reply_to.reply_to_msg_id)
|
||||
reply_to_params = {"chat_id": key[0], 'message_ids': key[1]}
|
||||
else:
|
||||
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
|
||||
reply_to_params = {'chat_id': key[0], 'reply_to_message_ids': 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(
|
||||
replies=replies - 1,
|
||||
**reply_to_params
|
||||
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
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ async def parse_messages(
|
|||
|
||||
if replies:
|
||||
messages_with_replies = {
|
||||
i.id: i.reply_to
|
||||
i.id: i.reply_to.reply_to_msg_id
|
||||
for i in messages.messages
|
||||
if not isinstance(i, raw.types.MessageEmpty) and i.reply_to and isinstance(i.reply_to, raw.types.MessageReplyHeader)
|
||||
}
|
||||
|
|
@ -136,61 +136,27 @@ async def parse_messages(
|
|||
# We need a chat id, but some messages might be empty (no chat attribute available)
|
||||
# Scan until we find a message with a chat available (there must be one, because we are fetching replies)
|
||||
for m in parsed_messages:
|
||||
if not isinstance(m, types.Message):
|
||||
continue
|
||||
|
||||
if m.chat:
|
||||
chat_id = m.chat.id
|
||||
break
|
||||
else:
|
||||
chat_id = 0
|
||||
|
||||
is_all_within_chat = not any(
|
||||
value.reply_to_peer_id
|
||||
for value in messages_with_replies.values()
|
||||
reply_messages = await client.get_messages(
|
||||
chat_id,
|
||||
reply_to_message_ids=messages_with_replies.keys(),
|
||||
replies=replies - 1
|
||||
)
|
||||
reply_messages: List[pyrogram.types.Message] = []
|
||||
if is_all_within_chat:
|
||||
# fast path: fetch all messages within the same chat
|
||||
reply_messages = await client.get_messages(
|
||||
chat_id,
|
||||
reply_to_message_ids=messages_with_replies.keys(),
|
||||
replies=replies - 1
|
||||
)
|
||||
else:
|
||||
# slow path: fetch all messages individually
|
||||
for target_reply_to in messages_with_replies.values():
|
||||
to_be_added_msg = None
|
||||
the_chat_id = chat_id
|
||||
if target_reply_to.reply_to_peer_id:
|
||||
the_chat_id = get_channel_id(target_reply_to.reply_to_peer_id.channel_id)
|
||||
to_be_added_msg = await client.get_messages(
|
||||
chat_id=the_chat_id,
|
||||
message_ids=target_reply_to.reply_to_msg_id,
|
||||
replies=replies - 1
|
||||
)
|
||||
if isinstance(to_be_added_msg, list):
|
||||
for current_to_be_added in to_be_added_msg:
|
||||
reply_messages.append(current_to_be_added)
|
||||
elif to_be_added_msg:
|
||||
reply_messages.append(to_be_added_msg)
|
||||
|
||||
for message in parsed_messages:
|
||||
reply_to = messages_with_replies.get(message.id, None)
|
||||
if not reply_to:
|
||||
continue
|
||||
|
||||
reply_id = reply_to.reply_to_msg_id
|
||||
reply_id = messages_with_replies.get(message.id, None)
|
||||
|
||||
for reply in reply_messages:
|
||||
if reply.id == reply_id and not reply.forum_topic_created:
|
||||
message.reply_to_message = reply
|
||||
|
||||
if reply.id == reply_id:
|
||||
if not reply.forum_topic_created:
|
||||
message.reply_to_message = reply
|
||||
if message_reply_to_story:
|
||||
for m in parsed_messages:
|
||||
if not isinstance(m, types.Message):
|
||||
continue
|
||||
|
||||
if m.chat:
|
||||
chat_id = m.chat.id
|
||||
break
|
||||
|
|
@ -198,7 +164,7 @@ async def parse_messages(
|
|||
chat_id = 0
|
||||
|
||||
reply_messages = {}
|
||||
for msg_id in message_reply_to_story:
|
||||
for msg_id in message_reply_to_story.keys():
|
||||
reply_messages[msg_id] = await client.get_stories(
|
||||
message_reply_to_story[msg_id]['user_id'],
|
||||
message_reply_to_story[msg_id]['story_id']
|
||||
|
|
|
|||
Loading…
Reference in a new issue