File tree Expand file tree Collapse file tree
pyrogram/types/messages_and_media Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1585,25 +1585,30 @@ async def _parse(
15851585
15861586 @property
15871587 def link (self ) -> str :
1588- if (
1588+ # 1. Early exit for invalid chat types
1589+ if not (
15891590 self .chat and
15901591 self .chat .type in {
15911592 enums .ChatType .SUPERGROUP ,
15921593 enums .ChatType .CHANNEL
15931594 }
15941595 ):
1595- if self .chat .username :
1596- if self .chat .is_forum and self .is_topic_message :
1597- return f"https://t.me/{ self .chat .username } /{ self .message_thread_id } /{ self .id } "
1598- if self .chat .is_forum :
1599- return f"https://t.me/{ self .chat .username } /1/{ self .id } "
1600- return f"https://t.me/{ self .chat .username } /{ self .id } "
1601- if self .chat .is_forum and self .is_topic_message :
1602- return f"https://t.me/c/{ utils .get_channel_id (self .chat .id )} /{ self .message_thread_id } /{ self .id } "
1603- # https://t.me/c/1279877202/31475
1604- if self .chat .is_forum :
1605- return f"https://t.me/{ self .chat .username } /1/{ self .id } "
1606- return f"https://t.me/c/{ utils .get_channel_id (self .chat .id )} /{ self .id } "
1596+ return None
1597+
1598+ # 2. Determine the base chat identifier (Public Username vs. Private Chat ID)
1599+ if self .chat .username :
1600+ chat_path = self .chat .username
1601+ else :
1602+ chat_path = f"c/{ utils .get_channel_id (self .chat .id )} "
1603+
1604+ # 3. Determine the message/thread routing
1605+ if self .chat .is_forum :
1606+ # If it's a forum but not a specific topic message, it defaults to topic 1 (General)
1607+ thread_id = self .message_thread_id if self .is_topic_message else 1
1608+ return f"https://t.me/{ chat_path } /{ thread_id } /{ self .id } "
1609+
1610+ # 4. Standard message link
1611+ return f"https://t.me/{ chat_path } /{ self .id } "
16071612
16081613 @property
16091614 def content (self ) -> Str :
You can’t perform that action at this time.
0 commit comments