mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-02 15:25:41 +00:00
client.join_chat() now returns pyrogram.Chat instead of MTProto Update (#206)
* client.join_chat() now returns pyrogram.Chat instead of MTProto Update * Do not use Chat._parse_mtproto_chat() method * Update chat.py Rename _parse_mtproto_chat to a generic _parse_chat_chat Hint about its current usage (none).
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
from ...ext import BaseClient
|
from ...ext import BaseClient
|
||||||
|
|
||||||
@@ -30,17 +31,24 @@ class JoinChat(BaseClient):
|
|||||||
Unique identifier for the target chat in form of a *t.me/joinchat/* link or username of the target
|
Unique identifier for the target chat in form of a *t.me/joinchat/* link or username of the target
|
||||||
channel/supergroup (in the format @username).
|
channel/supergroup (in the format @username).
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
On success, a :obj:`Chat <pyrogram.Chat>` object is returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
match = self.INVITE_LINK_RE.match(chat_id)
|
match = self.INVITE_LINK_RE.match(chat_id)
|
||||||
|
|
||||||
if match:
|
if match:
|
||||||
return self.send(
|
chat = self.send(
|
||||||
functions.messages.ImportChatInvite(
|
functions.messages.ImportChatInvite(
|
||||||
hash=match.group(1)
|
hash=match.group(1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
if isinstance(chat.chats[0], types.Chat):
|
||||||
|
return pyrogram.Chat._parse_chat_chat(self, chat.chats[0])
|
||||||
|
elif isinstance(chat.chats[0], types.Channel):
|
||||||
|
return pyrogram.Chat._parse_channel_chat(self, chat.chats[0])
|
||||||
else:
|
else:
|
||||||
resolved_peer = self.send(
|
resolved_peer = self.send(
|
||||||
functions.contacts.ResolveUsername(
|
functions.contacts.ResolveUsername(
|
||||||
@@ -53,8 +61,10 @@ class JoinChat(BaseClient):
|
|||||||
access_hash=resolved_peer.chats[0].access_hash
|
access_hash=resolved_peer.chats[0].access_hash
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.send(
|
chat = self.send(
|
||||||
functions.channels.JoinChannel(
|
functions.channels.JoinChannel(
|
||||||
channel=channel
|
channel=channel
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return pyrogram.Chat._parse_channel_chat(self, chat.chats[0])
|
||||||
|
@@ -209,3 +209,14 @@ class Chat(PyrogramType):
|
|||||||
parsed_chat.invite_link = full_chat.exported_invite.link
|
parsed_chat.invite_link = full_chat.exported_invite.link
|
||||||
|
|
||||||
return parsed_chat
|
return parsed_chat
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse_chat(client, chat):
|
||||||
|
# A wrapper around each entity parser: User, Chat and Channel.
|
||||||
|
# Currently unused, might become useful in future.
|
||||||
|
if isinstance(chat, types.Chat):
|
||||||
|
return Chat._parse_chat_chat(client, chat)
|
||||||
|
elif isinstance(chat, types.User):
|
||||||
|
return Chat._parse_user_chat(client, chat)
|
||||||
|
else:
|
||||||
|
return Chat._parse_channel_chat(client, chat)
|
||||||
|
Reference in New Issue
Block a user