Skip to content

Commit

Permalink
Add topic support in search_messages
Browse files Browse the repository at this point in the history
  • Loading branch information
KurimuzonAkuma committed Oct 18, 2024
1 parent b065377 commit c544532
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions pyrogram/methods/messages/search_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -55,6 +56,7 @@ async def get_chunk(
if from_user
else None
),
top_msg_id=message_thread_id,
hash=0
),
sleep_threshold=60
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c544532

Please sign in to comment.