diff --git a/pyrogram/types/messages_and_media/reaction.py b/pyrogram/types/messages_and_media/reaction.py index 83dda582..9d6b9e24 100644 --- a/pyrogram/types/messages_and_media/reaction.py +++ b/pyrogram/types/messages_and_media/reaction.py @@ -16,7 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Optional + import pyrogram +from pyrogram import raw from ..object import Object @@ -24,26 +27,53 @@ class Reaction(Object): """Contains information about a reaction. Parameters: - emoji (``str``): + emoji (``str``, *optional*): Reaction emoji. - count (``int``): - Reaction count. + custom_emoji_id (``int``, *optional*): + Custom emoji id. - chosen (``bool``): - Whether this is the chosen reaction. + count (``int``, *optional*): + Reaction count. """ def __init__( self, *, client: "pyrogram.Client" = None, - emoji: str, - count: int, - chosen: bool + emoji: Optional[str] = None, + custom_emoji_id: Optional[int] = None, + count: Optional[int] = None ): super().__init__(client) self.emoji = emoji + self.custom_emoji_id = custom_emoji_id self.count = count - self.chosen = chosen + + @staticmethod + def _parse( + client: "pyrogram.Client", + reaction: "raw.base.Reaction" + ) -> "Reaction": + if isinstance(reaction, raw.types.ReactionEmoji): + return Reaction( + client=client, + emoji=reaction.emoticon + ) + + if isinstance(reaction, raw.types.ReactionCustomEmoji): + return Reaction( + client=client, + custom_emoji_id=reaction.document_id + ) + + @staticmethod + def _parse_count( + client: "pyrogram.Client", + reaction_count: "raw.base.ReactionCount" + ) -> "Reaction": + reaction = Reaction._parse(client, reaction_count.reaction) + reaction.count = reaction_count.count + + return reaction