1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
1919import io
20+ import logging
2021from datetime import datetime
2122from typing import Callable , Optional , Union
2223
2728from .message import Str
2829from pyrogram .errors import RPCError
2930
31+ log = logging .getLogger (__name__ )
32+
3033
3134class Story (Object , Update ):
3235 """This object represents a story.
@@ -56,8 +59,6 @@ class Story(Object, Update):
5659 privacy_settings (:obj:`~pyrogram.types.StoryPrivacySettings`, *optional*):
5760 Privacy rules affecting story visibility; may be approximate for non-owned stories.
5861
59- TODO: //@content Content of the story
60-
6162 media (:obj:`~pyrogram.enums.MessageMediaType`, *optional*):
6263 The media type of the Story.
6364 This field will contain the enumeration type of the media message.
@@ -101,27 +102,6 @@ class Story(Object, Update):
101102 link (``str``, *property*):
102103 Generate a link to this story, only for Telegram Premium chats having usernames. Can be None if the story cannot have a link.
103104
104- can_be_deleted (``bool``, *property*):
105- True, if the story can be deleted
106-
107- can_be_edited (``bool``, *property*):
108- True, if the story can be edited
109-
110- can_be_forwarded (``bool``, *property*):
111- True, if the story can be forwarded as a message. Otherwise, screenshots and saving of the story content must be also forbidden
112-
113- can_be_replied (``bool``, *property*):
114- True, if the story can be replied in the chat with the story sender
115-
116- can_toggle_is_posted_to_chat_page (``bool``, *property*):
117- True, if the story's is_posted_to_chat_page value can be changed
118-
119- can_get_statistics (``bool``, *property*):
120- True, if the story statistics are available through getStoryStatistics
121-
122- can_get_interactions (``bool``, *property*):
123- True, if interactions with the story can be received through getStoryInteractions
124-
125105 """
126106
127107 def __init__ (
@@ -331,7 +311,23 @@ async def _parse(
331311 chat = types .Chat ._parse_chat (client , chats .get (raw_peer_id ))
332312 story_id = getattr (reply_story , "story_id" , None )
333313
334- if story_id and not (client .me and client .me .is_bot ):
314+ if story_update :
315+ rawupdate = story_update
316+
317+ raw_peer_id = utils .get_raw_peer_id (story_update .peer )
318+ if isinstance (story_update .peer , raw .types .PeerUser ):
319+ chat = types .Chat ._parse_chat (client , users .get (raw_peer_id ))
320+ else :
321+ chat = types .Chat ._parse_chat (client , chats .get (raw_peer_id ))
322+
323+ story_id = getattr (story_update .story , "id" , None )
324+ story_item = story_update .story
325+
326+ if (
327+ not story_item and
328+ story_id and
329+ not (client .me and client .me .is_bot )
330+ ):
335331 try :
336332 story_item = (
337333 await client .invoke (
@@ -343,68 +339,19 @@ async def _parse(
343339 ).stories [0 ]
344340 except (RPCError , IndexError ):
345341 pass
346- else :
347- (
348- date ,
349- expire_date ,
350- media ,
351- has_protected_content ,
352- photo ,
353- video ,
354- is_edited ,
355- is_posted_to_chat_page ,
356- caption ,
357- caption_entities ,
358- views ,
359- forwards ,
360- reactions ,
361- skipped ,
362- deleted ,
363- is_visible_only_for_self ,
364- areas ,
365- privacy_settings ,
366- ) = Story ._parse_story_item (client , story_item )
367-
368- if story_update :
369- rawupdate = story_update
370-
371- raw_peer_id = utils .get_raw_peer_id (story_update .peer )
372- if isinstance (story_update .peer , raw .types .PeerUser ):
373- chat = types .Chat ._parse_chat (client , users .get (raw_peer_id ))
374- else :
375- chat = types .Chat ._parse_chat (client , chats .get (raw_peer_id ))
376-
377- story_id = getattr (story_update .story , "id" , None )
378- (
379- date ,
380- expire_date ,
381- media ,
382- has_protected_content ,
383- photo ,
384- video ,
385- is_edited ,
386- is_posted_to_chat_page ,
387- caption ,
388- caption_entities ,
389- views ,
390- forwards ,
391- reactions ,
392- skipped ,
393- deleted ,
394- is_visible_only_for_self ,
395- areas ,
396- privacy_settings ,
397- ) = Story ._parse_story_item (client , story_update .story )
398342
399343 if peer :
400344 raw_peer_id = utils .get_raw_peer_id (peer )
401345 if isinstance (peer , raw .types .PeerUser ):
402346 chat = types .Chat ._parse_chat (client , users .get (raw_peer_id ))
403347 else :
404348 chat = types .Chat ._parse_chat (client , chats .get (raw_peer_id ))
405-
349+
406350 if story_item :
407- story_id = getattr (story_item , "id" , None )
351+ rawupdate = story_item
352+
353+ if not story_id :
354+ story_id = getattr (story_item , "id" , None )
408355 (
409356 date ,
410357 expire_date ,
@@ -426,6 +373,17 @@ async def _parse(
426373 privacy_settings ,
427374 ) = Story ._parse_story_item (client , story_item )
428375
376+ if not chat and story_item .from_id :
377+ peer_id = utils .get_peer_id (story_item .from_id )
378+ if isinstance (story_item .from_id , raw .types .PeerUser ):
379+ chat = types .Chat ._parse_user_chat (client , users .get (peer_id , None ))
380+ elif isinstance (story_item .from_id , raw .types .PeerChat ):
381+ chat = types .Chat ._parse_chat_chat (client , chats .get (peer_id , None ))
382+ else :
383+ chat = types .Chat ._parse_channel_chat (client , chats .get (peer_id , None ))
384+
385+ # fwd_from:flags.17?StoryFwdHeader
386+
429387 return Story (
430388 client = client ,
431389 _raw = rawupdate ,
@@ -615,6 +573,18 @@ def link(self) -> str:
615573 if self .chat and self .chat .username :
616574 return f"https://t.me/{ self .chat .username } /s/{ self .id } "
617575
576+ @property
577+ def edited (self ) -> bool :
578+ log .warning (
579+ "This property is deprecated. "
580+ "Please use is_edited instead"
581+ )
582+ return self .is_edited
618583
619- # edited: bool = None,
620- # pinned: bool = None,
584+ @property
585+ def pinned (self ) -> bool :
586+ log .warning (
587+ "This property is deprecated. "
588+ "Please use is_posted_to_chat_page instead"
589+ )
590+ return self .is_posted_to_chat_page
0 commit comments