Skip to content

Commit

Permalink
pyrofork: Fix story parser
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jun 15, 2024
1 parent c724b78 commit 6413530
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
3 changes: 2 additions & 1 deletion pyrogram/types/messages_and_media/message_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from pyrogram import raw, types, utils
from ..object import Object
from typing import Union


class MessageStory(Object):
Expand Down Expand Up @@ -53,7 +54,7 @@ def __init__(
async def _parse(
client: "pyrogram.Client",
message_story: "raw.types.MessageMediaStory"
) -> "MessageStory":
) -> Union["MessageStory", "types.Story"]:
from_user = None
sender_chat = None
user_id = None
Expand Down
41 changes: 26 additions & 15 deletions pyrogram/types/messages_and_media/story.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class Story(Object, Update):
id (``int``):
Unique story identifier.
chat (:obj:`~pyrogram.types.Chat`, *optional*):
Chat the story was sent in.
from_user (:obj:`~pyrogram.types.User`, *optional*):
Sender of the story.
Expand Down Expand Up @@ -180,7 +177,12 @@ def __init__(
async def _parse(
client: "pyrogram.Client",
stories: raw.base.StoryItem,
peer: Union["raw.types.PeerChannel", "raw.types.PeerUser"]
peer: Union[
"raw.types.PeerChannel",
"raw.types.PeerUser",
"raw.types.InputPeerChannel",
"raw.types.InputPeerUser"
]
) -> "Story":
if isinstance(stories, raw.types.StoryItemSkipped):
return await types.StorySkipped._parse(client, stories, peer)
Expand Down Expand Up @@ -229,20 +231,30 @@ async def _parse(
id=[await client.resolve_peer(chat_id)]
)
)
if stories.from_id is not None:
if getattr(stories.from_id, "user_id", None) is not None:
from_user = await client.get_users(stories.from_id.user_id)
chat = types.Chat._parse_chat(client, chat.chats[0])
elif getattr(stories.from_id, "channel_id", None) is not None:
sender_chat = types.Chat._parse_chat(client, stories.from_id.channel_id)
elif getattr(stories.from_id, "chat_id", None) is not None:
sender_chat = types.Chat._parse_chat(client, stories.from_id.chat_id)
else:
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
elif isinstance(peer, raw.types.InputPeerSelf):
from_user = client.me
else:
from_user = await client.get_users(peer.user_id)

from_id = getattr(stories, "from_id", None)
if from_id is not None:
if getattr(from_id, "user_id", None) is not None:
from_user = await client.get_users(getattr(from_id, "user_id"))
elif getattr(from_id, "channel_id", None) is not None:
chat = await client.invoke(
raw.functions.channels.GetChannels(
id=[await client.resolve_peer(utils.get_channel_id(getattr(from_id, "channel_id")))]
)
)
sender_chat = types.Chat._parse_chat(client, chat.chats[0])
elif getattr(from_id, "chat_id", None) is not None:
chat = await client.invoke(
raw.functions.channels.GetChannels(
id=[await client.resolve_peer(utils.get_channel_id(getattr(from_id, "chat_id")))]
)
)
sender_chat = types.Chat._parse_chat(client, chat.chats[0])

for priv in stories.privacy:
if isinstance(priv, raw.types.PrivacyValueAllowAll):
Expand Down Expand Up @@ -281,7 +293,6 @@ async def _parse(

return Story(
id=stories.id,
chat=chat,
from_user=from_user,
sender_chat=sender_chat,
date=utils.timestamp_to_datetime(stories.date),
Expand Down

0 comments on commit 6413530

Please sign in to comment.