mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 04:35:24 +00:00
Add force_full parameter in get_chat method
This commit is contained in:
parent
0d2bd64871
commit
5e543d3afc
@ -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,6 +82,7 @@ class GetChat:
|
||||
|
||||
peer = await self.resolve_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)):
|
||||
@ -85,3 +91,15 @@ class GetChat:
|
||||
r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
|
||||
|
||||
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]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user