Skip to content

Commit 44727ee

Browse files
committed
fix: message link in case of non-forum chats
Follow-Up: https://t.me/c/1220993104/1398843 Follow-Up: https://t.me/c/1220993104/1398881 Follow-Up: https://t.me/c/1220993104/1398950
1 parent 8087cbc commit 44727ee

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

pyrogram/types/messages_and_media/message.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Message(Object, Update):
6464
Unique message identifier inside this chat.
6565
6666
message_thread_id (``int``, *optional*):
67-
Unique identifier of a message thread to which the message belongs; for supergroups only
67+
Unique identifier of a message thread or forum topic to which the message belongs; for supergroups and private chats only.
6868
6969
direct_messages_topic (:obj:`~pyrogram.types.DirectMessagesTopic`, *optional*):
7070
Information about the direct messages chat topic that contains the message.
@@ -1522,28 +1522,24 @@ async def _parse(
15221522
if getattr(message, "reply_to", None):
15231523
parsed_message.reply_to_message_id = None
15241524
parsed_message.message_thread_id = None
1525+
1526+
if isinstance(message.reply_to, raw.types.MessageReplyStoryHeader):
1527+
parsed_message.reply_to_story = await types.Story._parse(client, users, chats, None, message.reply_to, None, None, None)
1528+
15251529
if isinstance(message.reply_to, raw.types.MessageReplyHeader):
15261530
parsed_message.reply_to_checklist_task_id = message.reply_to.todo_item_id
15271531
parsed_message.reply_to_message_id = message.reply_to.reply_to_msg_id
15281532
parsed_message.message_thread_id = message.reply_to.reply_to_top_id
15291533
if message.reply_to.forum_topic:
15301534
parsed_message.is_topic_message = True
1531-
if message.reply_to.reply_to_top_id:
1532-
parsed_message.message_thread_id = message.reply_to.reply_to_top_id
1533-
else:
1534-
parsed_message.message_thread_id = message.reply_to.reply_to_msg_id
1535-
if not parsed_message.message_thread_id:
1536-
parsed_message.message_thread_id = 1 # https://t.me/c/1279877202/31475
1535+
15371536
parsed_message.quote = types.TextQuote._parse(
15381537
client,
15391538
chats,
15401539
users,
15411540
message.reply_to
15421541
)
15431542

1544-
if isinstance(message.reply_to, raw.types.MessageReplyStoryHeader):
1545-
parsed_message.reply_to_story = await types.Story._parse(client, users, chats, None, message.reply_to, None, None, None)
1546-
15471543
if replies:
15481544
try:
15491545
key = (parsed_message.chat.id, parsed_message.reply_to_message_id)
@@ -1560,6 +1556,9 @@ async def _parse(
15601556
except MessageIdsEmpty:
15611557
pass
15621558

1559+
if parsed_message.chat.is_forum and not parsed_message.message_thread_id:
1560+
parsed_message.message_thread_id = 1 # https://t.me/c/1279877202/31475
1561+
15631562
if business_connection_id:
15641563
parsed_message.business_connection_id = business_connection_id
15651564
if raw_reply_to_message:
@@ -1596,11 +1595,15 @@ def link(self) -> str:
15961595
}
15971596
):
15981597
if self.chat.username:
1598+
if self.chat.is_forum and self.is_topic_message:
1599+
return f"https://t.me/{self.chat.username}/{self.message_thread_id}/{self.id}"
15991600
if self.chat.is_forum:
1600-
return f"https://t.me/{self.chat.username}{f'/{self.message_thread_id}' if self.message_thread_id else ''}/{self.id}"
1601+
return f"https://t.me/{self.chat.username}/1/{self.id}"
16011602
return f"https://t.me/{self.chat.username}/{self.id}"
1603+
if self.chat.is_forum and self.is_topic_message:
1604+
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.message_thread_id}/{self.id}"
16021605
if self.chat.is_forum:
1603-
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}{f'/{self.message_thread_id}' if self.message_thread_id else ''}/{self.id}"
1606+
return f"https://t.me/{self.chat.username}/1/{self.id}"
16041607
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.id}"
16051608

16061609
@property

0 commit comments

Comments
 (0)