From c5445324f712f2bf9942954e3a88b46bfb086efd Mon Sep 17 00:00:00 2001 From: KurimuzonAkuma Date: Fri, 18 Oct 2024 11:51:53 +0300 Subject: [PATCH] Add topic support in search_messages --- pyrogram/methods/messages/search_messages.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pyrogram/methods/messages/search_messages.py b/pyrogram/methods/messages/search_messages.py index 38cd303672..153a22a2b3 100644 --- a/pyrogram/methods/messages/search_messages.py +++ b/pyrogram/methods/messages/search_messages.py @@ -36,7 +36,8 @@ async def get_chunk( limit: int = 100, min_id: int = 0, max_id: int = 0, - from_user: Union[int, str] = None + from_user: Union[int, str] = None, + message_thread_id: Optional[int] = None ) -> List["types.Message"]: r = await client.invoke( raw.functions.messages.Search( @@ -55,6 +56,7 @@ async def get_chunk( if from_user else None ), + top_msg_id=message_thread_id, hash=0 ), sleep_threshold=60 @@ -77,7 +79,8 @@ async def search_messages( max_id: int = 0, filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY, limit: int = 0, - from_user: Union[int, str] = None + from_user: Union[int, str] = None, + message_thread_id: Optional[int] = None ) -> AsyncGenerator["types.Message", None]: """Search for text and media messages inside a specific chat. @@ -114,7 +117,7 @@ async def search_messages( If a positive value was provided, the method will return only messages with IDs more than min_id. max_id (``int``, *optional*): - If a positive value was provided, the method will return only messages with IDs less than max_id. + If a positive value was provided, the method will return only messages with IDs less than max_id. filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*): Pass a filter in order to search for specific kind of messages only. @@ -127,6 +130,10 @@ async def search_messages( from_user (``int`` | ``str``, *optional*): Unique identifier (int) or username (str) of the target user you want to search for messages from. + message_thread_id (``int``, *optional*): + Unique identifier for the target message thread (topic) of the forum. + For supergroups only. + Returns: ``Generator``: A generator yielding :obj:`~pyrogram.types.Message` objects. @@ -165,7 +172,8 @@ async def search_messages( min_id=min_id, max_id=max_id, limit=limit, - from_user=from_user + from_user=from_user, + message_thread_id=message_thread_id ) if not messages: