diff --git a/readthedocs/misc/v2-migration-guide.rst b/readthedocs/misc/v2-migration-guide.rst index 91ec043d..10556cc0 100644 --- a/readthedocs/misc/v2-migration-guide.rst +++ b/readthedocs/misc/v2-migration-guide.rst @@ -752,3 +752,10 @@ renamed send_read_acknowledge. add send_read_acknowledge as alias for mark_read? force sms removed as it was broken anyway and not very reliable you can now await client.action for a one-off any action not just cancel + +fwd msg and delete msg now mandate a list rather than a single int or msg +(since there's msg.delete and msg.forward_to this should be no issue). +they are meant to work on lists. + +also mark read only supports single now. a list would just be max anyway. +removed max id since it's not really of much use. diff --git a/telethon/_client/messages.py b/telethon/_client/messages.py index f55fed8d..e85921f3 100644 --- a/telethon/_client/messages.py +++ b/telethon/_client/messages.py @@ -518,7 +518,7 @@ async def send_message( async def forward_messages( self: 'TelegramClient', entity: 'hints.EntityLike', - messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', + messages: 'typing.Union[typing.Sequence[hints.MessageIDLike]]', from_peer: 'hints.EntityLike' = None, *, background: bool = None, @@ -530,10 +530,6 @@ async def forward_messages( if as_album is not None: warnings.warn('the as_album argument is deprecated and no longer has any effect') - single = not utils.is_list_like(messages) - if single: - messages = (messages,) - entity = await self.get_input_entity(entity) if from_peer: @@ -639,16 +635,13 @@ async def edit_message( async def delete_messages( self: 'TelegramClient', entity: 'hints.EntityLike', - message_ids: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', + messages: 'typing.Union[typing.Sequence[hints.MessageIDLike]]', *, revoke: bool = True) -> 'typing.Sequence[_tl.messages.AffectedMessages]': - if not utils.is_list_like(message_ids): - message_ids = (message_ids,) - - message_ids = ( + messages = ( m.id if isinstance(m, ( _tl.Message, _tl.MessageService, _tl.MessageEmpty)) - else int(m) for m in message_ids + else int(m) for m in messages ) if entity: @@ -660,42 +653,36 @@ async def delete_messages( if ty == helpers._EntityType.CHANNEL: res = await self([_tl.fn.channels.DeleteMessages( - entity, list(c)) for c in utils.chunks(message_ids)]) + entity, list(c)) for c in utils.chunks(messages)]) else: res = await self([_tl.fn.messages.DeleteMessages( - list(c), revoke) for c in utils.chunks(message_ids)]) + list(c), revoke) for c in utils.chunks(messages)]) return sum(r.pts_count for r in res) async def mark_read( self: 'TelegramClient', entity: 'hints.EntityLike', - message: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]' = None, + message: 'hints.MessageIDLike' = None, *, - max_id: int = None, clear_mentions: bool = False) -> bool: - if max_id is None: - if not message: - max_id = 0 - else: - if utils.is_list_like(message): - max_id = max(msg.id for msg in message) - else: - max_id = message.id + if not message: + max_id = 0 + elif isinstance(message, int): + max_id = message + else: + max_id = message.id entity = await self.get_input_entity(entity) if clear_mentions: await self(_tl.fn.messages.ReadMentions(entity)) - if max_id is None: - return True - if max_id is not None: - if helpers._entity_type(entity) == helpers._EntityType.CHANNEL: - return await self(_tl.fn.channels.ReadHistory( - utils.get_input_channel(entity), max_id=max_id)) - else: - return await self(_tl.fn.messages.ReadHistory( - entity, max_id=max_id)) + if helpers._entity_type(entity) == helpers._EntityType.CHANNEL: + return await self(_tl.fn.channels.ReadHistory( + utils.get_input_channel(entity), max_id=max_id)) + else: + return await self(_tl.fn.messages.ReadHistory( + entity, max_id=max_id)) return False diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index c4b9467b..d5a2fab7 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -2254,7 +2254,7 @@ class TelegramClient: async def forward_messages( self: 'TelegramClient', entity: 'hints.EntityLike', - messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', + messages: 'typing.Union[typing.Sequence[hints.MessageIDLike]]', from_peer: 'hints.EntityLike' = None, *, background: bool = None, @@ -2276,8 +2276,8 @@ class TelegramClient: entity (`entity`): To which entity the message(s) will be forwarded. - messages (`list` | `int` | `Message `): - The message(s) to forward, or their integer IDs. + messages (`list`): + The messages to forward, or their integer IDs. from_peer (`entity`): If the given messages are integer IDs and not instances @@ -2465,7 +2465,7 @@ class TelegramClient: async def delete_messages( self: 'TelegramClient', entity: 'hints.EntityLike', - message_ids: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', + messages: 'typing.Union[typing.Sequence[hints.MessageIDLike]]', *, revoke: bool = True) -> 'typing.Sequence[_tl.messages.AffectedMessages]': """ @@ -2486,8 +2486,8 @@ class TelegramClient: be `None` for normal chats, but **must** be present for channels and megagroups. - message_ids (`list` | `int` | `Message `): - The IDs (or ID) or messages to be deleted. + messages (`list`): + The messages to delete, or their integer IDs. revoke (`bool`, optional): Whether the message should be deleted for everyone or not. @@ -2517,9 +2517,8 @@ class TelegramClient: async def mark_read( self: 'TelegramClient', entity: 'hints.EntityLike', - message: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]' = None, + message: 'hints.MessageIDLike' = None, *, - max_id: int = None, clear_mentions: bool = False) -> bool: """ Marks messages as read and optionally clears mentions. @@ -2527,8 +2526,8 @@ class TelegramClient: This effectively marks a message as read (or more than one) in the given conversation. - If neither message nor maximum ID are provided, all messages will be - marked as read by assuming that ``max_id = 0``. + If no message or maximum ID is provided, all messages will be + marked as read. If a message or maximum ID is provided, all the messages up to and including such ID will be marked as read (for all messages whose ID @@ -2540,8 +2539,9 @@ class TelegramClient: entity (`entity`): The chat where these messages are located. - message (`list` | `Message `): - Either a list of messages or a single message. + message (`Message `): + The last (most-recent) message which was read, or its ID. + This is only useful if you want to mark a chat as partially read. max_id (`int`): Until which message should the read acknowledge be sent for.