|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import List |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram.api import types |
| 23 | +from .chat_photo import ChatPhoto |
| 24 | +from ..pyrogram_type import PyrogramType |
| 25 | +from ..user_and_chats.user import User |
| 26 | + |
| 27 | + |
| 28 | +class ChatPreview(PyrogramType): |
| 29 | + """This object represents a chat preview. |
| 30 | +
|
| 31 | + Args: |
| 32 | + title (``str``): |
| 33 | + Title of the chat. |
| 34 | +
|
| 35 | + photo (:obj:`ChatPhoto`): |
| 36 | + Chat photo. Suitable for downloads only. |
| 37 | +
|
| 38 | + type (``str``): |
| 39 | + Type of chat, can be either, "group", "supergroup" or "channel". |
| 40 | +
|
| 41 | + members_count (``int``): |
| 42 | + Chat members count. |
| 43 | +
|
| 44 | + members (List of :obj:`User`, *optional*): |
| 45 | + Preview of some of the chat members. |
| 46 | + """ |
| 47 | + |
| 48 | + def __init__(self, |
| 49 | + *, |
| 50 | + client: "pyrogram.client.ext.BaseClient", |
| 51 | + title: str, |
| 52 | + photo: ChatPhoto, |
| 53 | + type: str, |
| 54 | + members_count: int, |
| 55 | + members: List[User] = None): |
| 56 | + super().__init__(client) |
| 57 | + |
| 58 | + self.title = title |
| 59 | + self.photo = photo |
| 60 | + self.type = type |
| 61 | + self.members_count = members_count |
| 62 | + self.members = members |
| 63 | + |
| 64 | + @staticmethod |
| 65 | + def _parse(client, chat_invite: types.ChatInvite) -> "ChatPreview": |
| 66 | + return ChatPreview( |
| 67 | + title=chat_invite.title, |
| 68 | + photo=ChatPhoto._parse(client, chat_invite.photo), |
| 69 | + type=("group" if not chat_invite.channel else |
| 70 | + "channel" if chat_invite.broadcast else |
| 71 | + "supergroup"), |
| 72 | + members_count=chat_invite.participants_count, |
| 73 | + members=[User._parse(client, user) for user in chat_invite.participants] or None, |
| 74 | + client=client |
| 75 | + ) |
| 76 | + |
| 77 | + # TODO: Maybe just merge this object into Chat itself by adding the "members" field. |
| 78 | + # get_chat can be used as well instead of get_chat_preview |
0 commit comments