Skip to content

Commit 53d0cc3

Browse files
committed
Remove get_chat_preview and have get_chat deal with ChatPreview objects
1 parent 82c3bb2 commit 53d0cc3

4 files changed

Lines changed: 9 additions & 78 deletions

File tree

pyrogram/client/methods/chats/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from .get_chat_member import GetChatMember
2323
from .get_chat_members import GetChatMembers
2424
from .get_chat_members_count import GetChatMembersCount
25-
from .get_chat_preview import GetChatPreview
2625
from .get_dialogs import GetDialogs
2726
from .iter_chat_members import IterChatMembers
2827
from .iter_dialogs import IterDialogs
@@ -61,7 +60,6 @@ class Chats(
6160
UnpinChatMessage,
6261
GetDialogs,
6362
GetChatMembersCount,
64-
GetChatPreview,
6563
IterDialogs,
6664
IterChatMembers,
6765
UpdateChatUsername,

pyrogram/client/methods/chats/get_chat.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class GetChat(BaseClient):
2727
def get_chat(
2828
self,
2929
chat_id: Union[int, str]
30-
) -> "pyrogram.Chat":
31-
"""Get up to date information about the chat.
30+
) -> Union["pyrogram.Chat", "pyrogram.ChatPreview"]:
31+
"""Get up to date information about a chat.
32+
3233
Information include current name of the user for one-on-one conversations, current username of a user, group or
3334
channel, etc.
3435
@@ -39,7 +40,8 @@ def get_chat(
3940
of the target channel/supergroup (in the format @username).
4041
4142
Returns:
42-
:obj:`Chat`: On success, a chat object is returned.
43+
:obj:`Chat` | :obj:`ChatPreview`: On success, if you've already joined the chat, a chat object is returned,
44+
otherwise, a chat preview object is returned.
4345
4446
Raises:
4547
RPCError: In case of a Telegram RPC error.
@@ -48,16 +50,14 @@ def get_chat(
4850
match = self.INVITE_LINK_RE.match(str(chat_id))
4951

5052
if match:
51-
h = match.group(1)
52-
5353
r = self.send(
5454
functions.messages.CheckChatInvite(
55-
hash=h
55+
hash=match.group(1)
5656
)
5757
)
5858

5959
if isinstance(r, types.ChatInvite):
60-
raise ValueError("You haven't joined \"t.me/joinchat/{}\" yet".format(h))
60+
return pyrogram.ChatPreview._parse(self, r)
6161

6262
self.fetch_peers([r.chat])
6363

pyrogram/client/methods/chats/get_chat_preview.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

pyrogram/client/types/user_and_chats/chat_preview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ChatPreview(PyrogramType):
3232
title (``str``):
3333
Title of the chat.
3434
35-
photo (:obj:`ChatPhoto`):
35+
photo (:obj:`ChatPhoto`, *optional*):
3636
Chat photo. Suitable for downloads only.
3737
3838
type (``str``):
@@ -52,7 +52,7 @@ def __init__(
5252
*,
5353
client: "pyrogram.BaseClient" = None,
5454
title: str,
55-
photo: ChatPhoto,
55+
photo: ChatPhoto = None,
5656
type: str,
5757
members_count: int,
5858
members: List[User] = None

0 commit comments

Comments
 (0)