diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 4c8b5312dd4..68ba2c2b1fc 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -42,7 +42,6 @@ from .sticker import Sticker from .stripped_thumbnail import StrippedThumbnail from .story import Story -from .story_views import StoryViews from .thumbnail import Thumbnail from .venue import Venue from .video import Video @@ -57,7 +56,7 @@ "Animation", "Audio", "BoostsStatus", "Contact", "Document", "ForumTopic", "ForumTopicCreated", "ForumTopicClosed", "ForumTopicReopened", "ForumTopicEdited", "GeneralTopicHidden", "GeneralTopicUnhidden", "Game", "GiftCode", "Giveaway", "Location", "Message", "MessageEntity", - "Photo", "Thumbnail", "StrippedThumbnail", "Story", "StoryViews", "Poll", "PollOption", - "Sticker", "Venue", "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", - "WebAppData", "MessageReactions", "MyBoost" + "Photo", "Thumbnail", "StrippedThumbnail", "Story", "Poll", "PollOption", "Sticker", "Venue", + "Video", "VideoNote", "Voice", "WebPage", "Dice", "Reaction", "WebAppData", "MessageReactions", + "MyBoost" ] diff --git a/pyrogram/types/messages_and_media/story.py b/pyrogram/types/messages_and_media/story.py index 0cc617ce4d2..aa439967ab5 100644 --- a/pyrogram/types/messages_and_media/story.py +++ b/pyrogram/types/messages_and_media/story.py @@ -98,9 +98,12 @@ class Story(Object, Update): caption_entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*): For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the caption. - views (:obj:`~pyrogram.types.StoryViews`, *optional*): + views (``int``, *optional*): Stories views. + forwards (``int``, *optional*): + Stories forwards. + privacy (:obj:`~pyrogram.enums.StoryPrivacyRules`, *optional*): Story privacy. @@ -110,6 +113,9 @@ class Story(Object, Update): disallowed_users (List of ``int`` | ``str``, *optional*): List of user_ids whos denied to view the story. + reactions (List of :obj:`~pyrogram.types.Reaction`): + List of the reactions to this story. + skipped (``bool``, *optional*): The story is skipped. A story can be skipped in case it was skipped. @@ -147,10 +153,12 @@ def __init__( selected_contacts: bool = None, caption: str = None, caption_entities: List["types.MessageEntity"] = None, - views: "types.StoryViews" = None, + views: int = None, + forwards: int = None, privacy: "enums.StoryPrivacyRules" = None, allowed_users: List[Union[int, str]] = None, disallowed_users: List[Union[int, str]] = None, + reactions: List["types.Reaction"] = None, skipped: bool = None, deleted: bool = None ): @@ -179,9 +187,11 @@ def __init__( self.caption = caption self.caption_entities = caption_entities self.views = views + self.forwards = forwards self.privacy = privacy self.allowed_users = allowed_users self.disallowed_users = disallowed_users + self.reactions = reactions self.skipped = skipped self.deleted = deleted @@ -230,6 +240,9 @@ async def _parse( allowed_users = None disallowed_users = None media_type = None + views = None + forwards = None + reactions = None from_user = types.User._parse(client, users.get(peer_id, None)) sender_chat = types.Chat._parse_channel_chat(client, chats[peer_id]) if not from_user else None @@ -239,9 +252,6 @@ async def _parse( return Story(client=client, id=story.id, deleted=True, from_user=from_user, sender_chat=sender_chat, chat=chat) if isinstance(story, raw.types.StoryItemSkipped): return Story(client=client, id=story.id, skipped=True, from_user=from_user, sender_chat=sender_chat, chat=chat) - if isinstance(story, raw.types.MessageMediaStory): - return client.get_stories(chat.id, story.id) - return Story(client=client, id=story.id, from_user=from_user, sender_chat=sender_chat, chat=chat) forward_from = None forward_sender_name = None @@ -260,6 +270,14 @@ async def _parse( forward_from_chat = types.Chat._parse_channel_chat(client, chats[raw_peer_id]) forward_from_story_id = forward_header.story_id + if story.views: + views=getattr(story.views, "views_count", None) + forwards=getattr(story.views, "forwards_count", None) + reactions=[ + types.Reaction._parse_count(client, reaction) + for reaction in getattr(story.views, "reactions", []) + ] or None + if isinstance(story.media, raw.types.MessageMediaPhoto): photo = types.Photo._parse(client, story.media.photo, story.media.ttl_seconds) media_type = enums.MessageMediaType.PHOTO @@ -314,10 +332,12 @@ async def _parse( selected_contacts=story.selected_contacts, caption=story.caption, caption_entities=entities or None, - views=types.StoryViews._parse(client, story.views) if story.views else None, + views=views, + forwards=forwards, privacy=privacy, allowed_users=allowed_users, disallowed_users=disallowed_users, + reactions=reactions, client=client ) diff --git a/pyrogram/types/messages_and_media/story_views.py b/pyrogram/types/messages_and_media/story_views.py deleted file mode 100644 index 5137ffa6446..00000000000 --- a/pyrogram/types/messages_and_media/story_views.py +++ /dev/null @@ -1,75 +0,0 @@ -# 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 pyrogram import raw, types -from typing import List -from ..object import Object - -class StoryViews(Object): - """Contains information about a story viewers. - - Parameters: - views_count (``int`` ``32-bit``): - Views count. - - has_viewers (``bool``, *optional*): - Has viewers. - - forwards_count (``int`` ``32-bit``, *optional*): - Forwards count. - - reactions (List of :obj:`~pyrogram.types.Reaction`, *optional*): - Reactions list. - - reactions_count (``int`` ``32-bit``, *optional*): - Reactions count. - - recent_viewers (List of ``int`` ``64-bit``, *optional*): - Viewers list. - """ - - def __init__( - self, *, - views_count: int, - has_viewers: bool = None, - forwards_count: int = None, - reactions: List["types.Reaction"] = None, - reactions_count: int = None, - recent_viewers: List[int] = None - ): - super().__init__() - - self.views_count = views_count - self.has_viewers = has_viewers - self.forwards_count = forwards_count - self.reactions = reactions - self.reactions_count = reactions_count - self.recent_viewers = recent_viewers - - @staticmethod - def _parse(client, storyviews: "raw.types.StoryViews") -> "StoryViews": - return StoryViews( - views_count=getattr(storyviews, "views_count", None), - has_viewers=getattr(storyviews, "has_viewers", None), - forwards_count=getattr(storyviews, "forwards_count", None), - reactions=[ - types.Reaction._parse_count(client, reaction) - for reaction in getattr(storyviews, "reactions", []) - ] or None, - recent_viewers=getattr(storyviews, "recent_viewers", None) or None, - )