Skip to content

Commit

Permalink
Add support for scheduled messages in iter_messages (#3127)
Browse files Browse the repository at this point in the history
  • Loading branch information
New-dev0 committed Aug 29, 2021
1 parent 828cf2d commit befba11
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions telethon/client/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class _MessagesIter(RequestIter):
"""
async def _init(
self, entity, offset_id, min_id, max_id,
from_user, offset_date, add_offset, filter, search, reply_to
from_user, offset_date, add_offset, filter, search, reply_to,
scheduled
):
# Note that entity being `None` will perform a global search.
if entity:
Expand Down Expand Up @@ -84,6 +85,11 @@ async def _init(
offset_id=offset_id,
limit=1
)
elif scheduled:
self.request = functions.messages.GetScheduledHistoryRequest(
peer=entity,
hash=0
)
elif reply_to is not None:
self.request = functions.messages.GetRepliesRequest(
peer=self.entity,
Expand Down Expand Up @@ -336,7 +342,8 @@ def iter_messages(
wait_time: float = None,
ids: 'typing.Union[int, typing.Sequence[int]]' = None,
reverse: bool = False,
reply_to: int = None
reply_to: int = None,
scheduled: bool = False
) -> 'typing.Union[_MessagesIter, _IDsIter]':
"""
Iterator over the messages for the given chat.
Expand Down Expand Up @@ -463,6 +470,10 @@ def iter_messages(
a message and replies to it itself, that reply will not
be included in the results.
scheduled (`bool`, optional):
If set to `True`, messages which are scheduled will be returned.
All other parameter will be ignored for this, except `entity`.
Yields
Instances of `Message <telethon.tl.custom.message.Message>`.
Expand Down Expand Up @@ -521,7 +532,8 @@ def iter_messages(
add_offset=add_offset,
filter=filter,
search=search,
reply_to=reply_to
reply_to=reply_to,
scheduled=scheduled
)

async def get_messages(self: 'TelegramClient', *args, **kwargs) -> 'hints.TotalList':
Expand Down

0 comments on commit befba11

Please sign in to comment.