Add force_full parameter in get_chat method

This commit is contained in:
KurimuzonAkuma 2024-05-25 14:59:17 +03:00
parent 0d2bd64871
commit 5e543d3afc

View File

@ -27,7 +27,8 @@ from pyrogram import utils
class GetChat:
async def get_chat(
self: "pyrogram.Client",
chat_id: Union[int, str]
chat_id: Union[int, str],
force_full: bool = True
) -> Union["types.Chat", "types.ChatPreview"]:
"""Get up to date information about a chat.
@ -42,6 +43,10 @@ class GetChat:
Unique identifier for the target chat in form of a *t.me/joinchat/* link, identifier (int) or username
of the target channel/supergroup (in the format @username).
force_full (``bool``, *optional*):
Pass False, if you don't need to fetch full chat information.
Defaults to True.
Returns:
:obj:`~pyrogram.types.Chat` | :obj:`~pyrogram.types.ChatPreview`: On success, if you've already joined the chat, a chat object is returned,
otherwise, a chat preview object is returned.
@ -77,11 +82,24 @@ class GetChat:
peer = await self.resolve_peer(chat_id)
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.invoke(raw.functions.users.GetFullUser(id=peer))
else:
r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
if force_full:
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.invoke(raw.functions.users.GetFullUser(id=peer))
else:
r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
return await types.Chat._parse_full(self, r)
return await types.Chat._parse_full(self, r)
else:
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(raw.functions.channels.GetChannels(id=[peer]))
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.invoke(raw.functions.users.GetUsers(id=[peer]))
else:
r = await self.invoke(raw.functions.messages.GetChats(id=[peer.chat_id]))
return types.Chat._parse_chat(
self,
r.chats[0] if isinstance(r, raw.types.messages.Chats) else r[0]
)