Skip to content

Commit

Permalink
Added offset_id parameter in search_messages method (#78)
Browse files Browse the repository at this point in the history
* Update search_messages.py

Added offset_id
  • Loading branch information
Surendra9123 committed Jul 8, 2024
1 parent 7f55351 commit 7f6cf43
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions pyrogram/methods/messages/search_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union, List, AsyncGenerator, Optional
from datetime import datetime

import pyrogram
from pyrogram import raw, types, utils, enums
Expand All @@ -29,21 +30,26 @@ async def get_chunk(
query: str = "",
filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
offset: int = 0,
offset_id: int = 0,
min_date: datetime = utils.zero_datetime(),
max_date: datetime = utils.zero_datetime(),
limit: int = 100,
min_id: int = 0,
max_id: int = 0,
from_user: Union[int, str] = None
) -> List["types.Message"]:
r = await client.invoke(
raw.functions.messages.Search(
peer=await client.resolve_peer(chat_id),
q=query,
filter=filter.value(),
min_date=0,
max_date=0,
offset_id=0,
min_date=utils.datetime_to_timestamp(min_date),
max_date= utils.datetime_to_timestamp(max_date),
offset_id=offset_id,
add_offset=offset,
limit=limit,
min_id=0,
max_id=0,
min_id=min_id,
max_id=max_id,
from_id=(
await client.resolve_peer(from_user)
if from_user
Expand All @@ -64,6 +70,11 @@ async def search_messages(
chat_id: Union[int, str],
query: str = "",
offset: int = 0,
offset_id: int = 0,
min_date: datetime = utils.zero_datetime(),
max_date: datetime = utils.zero_datetime(),
min_id: int = 0,
max_id: int = 0,
filter: "enums.MessagesFilter" = enums.MessagesFilter.EMPTY,
limit: int = 0,
from_user: Union[int, str] = None
Expand All @@ -90,6 +101,21 @@ async def search_messages(
Sequential number of the first message to be returned.
Defaults to 0.
offset_id (``int``, *optional*):
Identifier of the first message to be returned.
min_date (:py:obj:`~datetime.datetime`, *optional*):
Pass a date as offset to retrieve only older messages starting from that date.
max_date (:py:obj:`~datetime.datetime`, *optional*):
Pass a date as offset to retrieve only newer messages starting from that date.
min_id (``int``, *optional*):
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.
filter (:obj:`~pyrogram.enums.MessagesFilter`, *optional*):
Pass a filter in order to search for specific kind of messages only.
Defaults to any message (no filter).
Expand Down Expand Up @@ -133,6 +159,11 @@ async def search_messages(
query=query,
filter=filter,
offset=offset,
offset_id=offset_id,
min_date=min_date,
max_date=max_date,
min_id=min_id,
max_id=max_id,
limit=limit,
from_user=from_user
)
Expand Down

0 comments on commit 7f6cf43

Please sign in to comment.