diff --git a/pyrogram/types/user_and_chats/__init__.py b/pyrogram/types/user_and_chats/__init__.py index 60ebd309..348ecd9f 100644 --- a/pyrogram/types/user_and_chats/__init__.py +++ b/pyrogram/types/user_and_chats/__init__.py @@ -29,6 +29,7 @@ from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chat_preview import ChatPreview from .chat_privileges import ChatPrivileges +from .chat_reactions import ChatReactions from .dialog import Dialog from .emoji_status import EmojiStatus from .invite_link_importer import InviteLinkImporter @@ -61,5 +62,6 @@ __all__ = [ "ChatJoinRequest", "ChatPrivileges", "ChatJoiner", - "EmojiStatus" + "EmojiStatus", + "ChatReactions" ] diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index dc345bbc..aa727952 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -126,7 +126,7 @@ class Chat(Object): The default "send_as" chat. Returned only in :meth:`~pyrogram.Client.get_chat`. - available_reactions (List of ``str``, *optional*): + available_reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*): Available reactions in the chat. Returned only in :meth:`~pyrogram.Client.get_chat`. """ @@ -162,7 +162,7 @@ class Chat(Object): distance: int = None, linked_chat: "types.Chat" = None, send_as_chat: "types.Chat" = None, - available_reactions: List[str] = None + available_reactions: Optional[List["types.Reaction"]] = None ): super().__init__(client) @@ -345,7 +345,7 @@ class Chat(Object): if isinstance(full_chat.exported_invite, raw.types.ChatInviteExported): parsed_chat.invite_link = full_chat.exported_invite.link - parsed_chat.available_reactions = full_chat.available_reactions or None + parsed_chat.available_reactions = types.ChatReactions._parse(client, full_chat.available_reactions) return parsed_chat diff --git a/pyrogram/types/user_and_chats/chat_reactions.py b/pyrogram/types/user_and_chats/chat_reactions.py new file mode 100644 index 00000000..057fb966 --- /dev/null +++ b/pyrogram/types/user_and_chats/chat_reactions.py @@ -0,0 +1,69 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Optional, List + +import pyrogram +from pyrogram import raw, types +from ..object import Object + + +class ChatReactions(Object): + """A chat reactions + + Parameters: + all_are_enabled (``bool``, *optional*) + + allow_custom_emoji (``bool``, *optional*): + Whether custom emoji are allowed or not. + + reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*): + Reactions available. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + all_are_enabled: Optional[bool] = None, + allow_custom_emoji: Optional[bool] = None, + reactions: Optional[List["types.Reaction"]] = None, + ): + super().__init__(client) + + self.all_are_enabled = all_are_enabled + self.allow_custom_emoji = allow_custom_emoji + self.reactions = reactions + + @staticmethod + def _parse(client, chat_reactions: "raw.base.ChatReactions") -> Optional["ChatReactions"]: + if isinstance(chat_reactions, raw.types.ChatReactionsAll): + return ChatReactions( + client=client, + all_are_enabled=True, + allow_custom_emoji=chat_reactions.allow_custom + ) + + if isinstance(chat_reactions, raw.types.ChatReactionsSome): + return ChatReactions( + client=client, + reactions=[types.Reaction._parse(client, reaction) + for reaction in chat_reactions.reactions] + ) + + return None