Skip to content

Commit e63849e

Browse files
committed
Add StoryRepostInfo
1 parent 44816f2 commit e63849e

File tree

7 files changed

+222
-3
lines changed

7 files changed

+222
-3
lines changed

compiler/docs/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,10 @@ def get_title_list(s: str) -> list:
726726
StoryAreaTypeWeather
727727
StoryAreaTypeUniqueGift
728728
StoryArea
729+
StoryRepostInfo
730+
StoryOrigin
731+
StoryOriginHiddenUser
732+
StoryOriginPublicStory
729733
StoryPrivacySettings
730734
StoryPrivacySettingsEveryone
731735
StoryPrivacySettingsContacts

pyrogram/types/stories/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@
3939
from .story_area_type_message import StoryAreaTypeMessage
4040
from .story_area_type_weather import StoryAreaTypeWeather
4141
from .story_area_type_unique_gift import StoryAreaTypeUniqueGift
42+
from .story_origin import StoryOrigin
43+
from .story_origin_hidden_user import StoryOriginHiddenUser
44+
from .story_origin_public_story import StoryOriginPublicStory
4245
from .story_privacy_settings import StoryPrivacySettings
4346
from .story_privacy_settings_everyone import StoryPrivacySettingsEveryone
4447
from .story_privacy_settings_contacts import StoryPrivacySettingsContacts
4548
from .story_privacy_settings_close_friends import StoryPrivacySettingsCloseFriends
4649
from .story_privacy_settings_selected_users import StoryPrivacySettingsSelectedUsers
50+
from .story_repost_info import StoryRepostInfo
4751
from .story_stealth_mode import StoryStealthMode
4852

4953

@@ -70,10 +74,14 @@
7074
"StoryAreaTypeMessage",
7175
"StoryAreaTypeWeather",
7276
"StoryAreaTypeUniqueGift",
77+
"StoryOrigin",
78+
"StoryOriginHiddenUser",
79+
"StoryOriginPublicStory",
7380
"StoryPrivacySettings",
7481
"StoryPrivacySettingsEveryone",
7582
"StoryPrivacySettingsContacts",
7683
"StoryPrivacySettingsCloseFriends",
7784
"StoryPrivacySettingsSelectedUsers",
85+
"StoryRepostInfo",
7886
"StoryStealthMode",
7987
]

pyrogram/types/stories/story.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class Story(Object, Update):
5656
is_visible_only_for_self (``bool``, *optional*):
5757
True, if the story is visible only for the current user.
5858
59+
repost_info (:obj:`~pyrogram.types.StoryRepostInfo`, *optional*):
60+
Information about the original story; may be None if the story wasn't reposted.
61+
5962
privacy_settings (:obj:`~pyrogram.types.StoryPrivacySettings`, *optional*):
6063
Privacy rules affecting story visibility; may be approximate for non-owned stories.
6164
@@ -115,6 +118,7 @@ def __init__(
115118
is_edited: bool = None,
116119
is_posted_to_chat_page: bool = None,
117120
is_visible_only_for_self: bool = None,
121+
repost_info: "types.StoryRepostInfo" = None,
118122
privacy_settings: "types.StoryPrivacySettings" = None,
119123
media: "enums.MessageMediaType" = None,
120124
photo: "types.Photo" = None,
@@ -139,6 +143,7 @@ def __init__(
139143
self.is_edited = is_edited
140144
self.is_posted_to_chat_page = is_posted_to_chat_page
141145
self.is_visible_only_for_self = is_visible_only_for_self
146+
self.repost_info = repost_info
142147
self.privacy_settings = privacy_settings
143148
self.media = media
144149
self.photo = photo
@@ -195,8 +200,6 @@ def _parse_story_item(
195200
is_visible_only_for_self = not story_item.public
196201

197202
# out:flags.16?true
198-
# from_id:flags.18?Peer
199-
# fwd_from:flags.17?StoryFwdHeader
200203
if story_item.privacy:
201204
privacy_settings = types.StoryPrivacySettings._parse(client, story_item.privacy)
202205

@@ -288,6 +291,7 @@ async def _parse(
288291
deleted = None
289292
areas = None
290293
privacy_settings = None
294+
repost_info = None
291295

292296
if story_media:
293297
rawupdate = story_media
@@ -382,7 +386,11 @@ async def _parse(
382386
else:
383387
chat = types.Chat._parse_channel_chat(client, chats.get(peer_id, None))
384388

385-
# fwd_from:flags.17?StoryFwdHeader
389+
if story_item.fwd_from:
390+
repost_info = types.StoryRepostInfo._parse(
391+
client, story_item.fwd_from,
392+
users, chats
393+
)
386394

387395
return Story(
388396
client=client,
@@ -407,6 +415,7 @@ async def _parse(
407415
deleted=deleted,
408416
areas=areas,
409417
privacy_settings=privacy_settings,
418+
repost_info=repost_info,
410419
)
411420

412421
async def react(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
from ..object import Object
21+
22+
23+
class StoryOrigin(Object):
24+
"""Contains information about the origin of a story that was reposted.
25+
26+
Currently, it can be one of:
27+
28+
- :obj:`~pyrogram.types.StoryOriginPublicStory`
29+
- :obj:`~pyrogram.types.StoryOriginHiddenUser`
30+
31+
"""
32+
33+
def __init__(self):
34+
super().__init__()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
from .story_origin import StoryOrigin
21+
22+
23+
class StoryOriginHiddenUser(StoryOrigin):
24+
"""The original story was posted by an unknown user.
25+
26+
Parameters:
27+
poster_name (``str``):
28+
Name of the user or the chat that posted the story.
29+
30+
"""
31+
32+
def __init__(
33+
self,
34+
*,
35+
poster_name: str = None
36+
):
37+
super().__init__()
38+
39+
self.poster_name = poster_name
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 types
22+
23+
from .story_origin import StoryOrigin
24+
25+
26+
class StoryOriginPublicStory(StoryOrigin):
27+
"""The original story was a public story that was posted by a known chat.
28+
29+
Parameters:
30+
chat (:obj:`~pyrogram.types.Chat`):
31+
Identifier of the chat that posted original story.
32+
33+
story_id (``int``):
34+
Story identifier of the original story.
35+
36+
"""
37+
38+
def __init__(
39+
self,
40+
*,
41+
chat: "types.Chat" = None,
42+
story_id: int = None
43+
):
44+
super().__init__()
45+
46+
self.chat = chat
47+
self.story_id = story_id
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)