From 27d6cce8e2716058f097219c536d3e530bd5e8c3 Mon Sep 17 00:00:00 2001 From: apepenkov Date: Thu, 9 Nov 2023 23:54:01 +0300 Subject: [PATCH] add abcs.Peer resolving to resolve_to_packed --- .../src/telethon/_impl/client/client/users.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/src/telethon/_impl/client/client/users.py b/client/src/telethon/_impl/client/client/users.py index ca45676a..7ccbddd5 100644 --- a/client/src/telethon/_impl/client/client/users.py +++ b/client/src/telethon/_impl/client/client/users.py @@ -172,6 +172,28 @@ async def resolve_to_packed(client: Client, chat: ChatLike) -> PackedChat: else: raise RuntimeError("unexpected case") + if isinstance(chat, abcs.Peer): + if isinstance(chat, types.PeerUser): + return PackedChat( + ty=PackedType.USER, + id=chat.user_id, + access_hash=0, + ) + elif isinstance(chat, types.PeerChat): + return PackedChat( + ty=PackedType.CHAT, + id=chat.chat_id, + access_hash=0, + ) + elif isinstance(chat, types.PeerChannel): + return PackedChat( + ty=PackedType.BROADCAST, + id=chat.channel_id, + access_hash=0, + ) + else: + raise RuntimeError("unexpected case") + if isinstance(chat, str): if chat.startswith("+"): resolved = await resolve_phone(client, chat)