Skip to content

Commit

Permalink
Add missing attributes to the Chat type
Browse files Browse the repository at this point in the history
Co-authored-by: wulan17 <wulan17@nusantararom.org>
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
KurimuzonAkuma and wulan17 committed Jan 3, 2024
1 parent 98374a3 commit 9721316
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class Chat(Object):
photo (:obj:`~pyrogram.types.ChatPhoto`, *optional*):
Chat photo. Suitable for downloads only.
stories (List of :obj:`~pyrogram.types.Story`, *optional*):
The list of chat's stories if available.
wallpaper (:obj:`~pyrogram.types.Document`, *optional*):
Chat wallpaper.
bio (``str``, *optional*):
Bio of the other party in a private chat.
Returned only in :meth:`~pyrogram.Client.get_chat`.
Expand All @@ -102,6 +108,9 @@ class Chat(Object):
It is accurate only in case the owner has set the chat photo, otherwise the dc_id will be the one assigned
to the administrator who set the current chat photo.
folder_id (``int``, *optional*):
The folder identifier where the chat is located.
has_protected_content (``bool``, *optional*):
True, if messages from the chat can't be forwarded to other chats.
Expand Down Expand Up @@ -155,10 +164,14 @@ class Chat(Object):
List of all chat (fragment) usernames; for private chats, supergroups and channels.
Returned only in :meth:`~pyrogram.Client.get_chat`.
reply_color (:obj:`~pyrogram.types.ChatColor`, *optional*)
level (``int``, *optional*):
Channel boosts level.
For channel only.
reply_color (:obj:`~pyrogram.types.ChatColor`, *optional*):
Chat reply color.
profile_color (:obj:`~pyrogram.types.ChatColor`, *optional*)
profile_color (:obj:`~pyrogram.types.ChatColor`, *optional*):
Chat profile color.
"""

Expand All @@ -184,9 +197,12 @@ def __init__(
first_name: str = None,
last_name: str = None,
photo: "types.ChatPhoto" = None,
stories: List["types.Story"] = None,
wallpaper: "types.Document" = None,
bio: str = None,
description: str = None,
dc_id: int = None,
folder_id: int = None,
has_protected_content: bool = None,
invite_link: str = None,
pinned_message=None,
Expand Down Expand Up @@ -223,9 +239,12 @@ def __init__(
self.first_name = first_name
self.last_name = last_name
self.photo = photo
self.stories = stories
self.wallpaper = wallpaper
self.bio = bio
self.description = description
self.dc_id = dc_id
self.folder_id = folder_id
self.has_protected_content = has_protected_content
self.invite_link = invite_link
self.pinned_message = pinned_message
Expand All @@ -244,7 +263,7 @@ def __init__(

@property
def full_name(self) -> str:
return " ".join(filter(None, [self.first_name, self.last_name])) or None
return " ".join(filter(None, [self.first_name, self.last_name])) or self.title or None

@staticmethod
def _parse_user_chat(client, user: raw.types.User) -> "Chat":
Expand Down Expand Up @@ -375,12 +394,27 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.

parsed_chat = Chat._parse_user_chat(client, users[full_user.id])
parsed_chat.bio = full_user.about
parsed_chat.folder_id = getattr(full_user, "folder_id", None)

if full_user.pinned_msg_id:
parsed_chat.pinned_message = await client.get_messages(
parsed_chat.id,
message_ids=full_user.pinned_msg_id
)

if getattr(full_user, "stories"):
peer_stories: raw.types.PeerStories = full_user.stories
parsed_chat.stories = types.List(
[
await types.Story._parse(
client, story, peer_stories.peer
)
for story in peer_stories.stories
]
) or None

if getattr(full_user, "wallpaper") and isinstance(full_user.wallpaper, raw.types.WallPaper):
parsed_chat.wallpaper = types.Document._parse(client, full_user.wallpaper.document, "wallpaper.jpg")
else:
full_chat = chat_full.full_chat
chat_raw = chats[full_chat.id]
Expand All @@ -400,6 +434,7 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.
parsed_chat.sticker_set_name = getattr(full_chat.stickerset, "short_name", None)
parsed_chat.is_participants_hidden = full_chat.participants_hidden
parsed_chat.is_antispam = full_chat.antispam
parsed_chat.folder_id = getattr(full_chat, "folder_id", None)

linked_chat_raw = chats.get(full_chat.linked_chat_id, None)

Expand All @@ -416,6 +451,20 @@ async def _parse_full(client, chat_full: Union[raw.types.messages.ChatFull, raw.

parsed_chat.send_as_chat = Chat._parse_chat(client, send_as_raw)

if getattr(full_chat, "stories"):
peer_stories: raw.types.PeerStories = full_chat.stories
parsed_chat.stories = types.List(
[
await types.Story._parse(
client, story, peer_stories.peer
)
for story in peer_stories.stories
]
) or None

if getattr(full_chat, "wallpaper") and isinstance(full_chat.wallpaper, raw.types.WallPaper):
parsed_chat.wallpaper = types.Document._parse(client, full_chat.wallpaper.document, "wallpaper.jpg")

if full_chat.pinned_msg_id:
parsed_chat.pinned_message = await client.get_messages(
parsed_chat.id,
Expand Down

0 comments on commit 9721316

Please sign in to comment.