|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present <https://github.com/TelegramPlayGround> |
| 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 | + |
| 20 | +import pyrogram |
| 21 | +from pyrogram import raw, types, utils |
| 22 | + |
| 23 | +from ..object import Object |
| 24 | + |
| 25 | + |
| 26 | +class StoryRepostInfo(Object): |
| 27 | + """Contains information about original story that was reposted. |
| 28 | +
|
| 29 | + Parameters: |
| 30 | + origin (:obj:`~pyrogram.types.StoryOrigin`): |
| 31 | + Origin of the story that was reposted. |
| 32 | +
|
| 33 | + is_content_modified (``bool``): |
| 34 | + True, if story content was modified during reposting; otherwise, story wasn't modified. |
| 35 | +
|
| 36 | + """ |
| 37 | + |
| 38 | + def __init__( |
| 39 | + self, |
| 40 | + *, |
| 41 | + origin: "types.StoryOrigin" = None, |
| 42 | + is_content_modified: bool = None |
| 43 | + ): |
| 44 | + super().__init__() |
| 45 | + |
| 46 | + self.origin = origin |
| 47 | + self.is_content_modified = is_content_modified |
| 48 | + |
| 49 | + @staticmethod |
| 50 | + def _parse( |
| 51 | + client: "pyrogram.Client", |
| 52 | + fwd_from: "raw.base.StoryFwdHeader", |
| 53 | + users: dict, |
| 54 | + chats: dict, |
| 55 | + ) -> "StoryRepostInfo": |
| 56 | + from_user = fwd_from.is_from |
| 57 | + origin = None |
| 58 | + if from_user: |
| 59 | + fwd_from_chat = None |
| 60 | + peer_id = utils.get_peer_id(from_user) |
| 61 | + if isinstance(from_user, raw.types.PeerUser): |
| 62 | + fwd_from_chat = types.Chat._parse_user_chat(client, users.get(peer_id, None)) |
| 63 | + elif isinstance(story_item.from_id, raw.types.PeerChat): |
| 64 | + fwd_from_chat = types.Chat._parse_chat_chat(client, chats.get(peer_id, None)) |
| 65 | + else: |
| 66 | + fwd_from_chat = types.Chat._parse_channel_chat(client, chats.get(peer_id, None)) |
| 67 | + origin = types.StoryOriginPublicStory( |
| 68 | + chat=fwd_from_chat, |
| 69 | + story_id=fwd_from.story_id |
| 70 | + ) |
| 71 | + else: |
| 72 | + origin = types.StoryOriginHiddenUser( |
| 73 | + poster_name=fwd_from.from_name |
| 74 | + ) |
| 75 | + return StoryRepostInfo( |
| 76 | + origin=origin, |
| 77 | + is_content_modified=fwd_from.modified |
| 78 | + ) |
0 commit comments