Skip to content

Commit dcdf65e

Browse files
Request GetChannels as required
1 parent 01290e8 commit dcdf65e

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

pyrogram/methods/stories/get_pinned_stories.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pyrogram
2222
from pyrogram import raw
2323
from pyrogram import types
24+
from pyrogram import utils
2425

2526

2627
class GetPinnedStories:
@@ -60,8 +61,9 @@ async def get_pinned_stories(
6061
total = abs(limit) or (1 << 31)
6162
limit = min(100, total)
6263

64+
peer = await self.resolve_peer(chat_id)
65+
6366
while True:
64-
peer = await self.resolve_peer(chat_id)
6567
r = await self.invoke(
6668
raw.functions.stories.GetPinnedStories(
6769
peer=peer,
@@ -73,15 +75,24 @@ async def get_pinned_stories(
7375
if not r.stories:
7476
return
7577

78+
users = {i.id: i for i in r.users}
79+
chats = {i.id: i for i in r.chats}
80+
81+
if isinstance(peer, raw.types.InputPeerChannel):
82+
peer_id = utils.get_input_peer_id(peer)
83+
if peer_id not in r.chats:
84+
channel = await self.invoke(raw.functions.channels.GetChannels(id=[peer]))
85+
chats.update({peer_id: channel.chats[0]})
86+
7687
last = r.stories[-1]
7788
offset_id = last.id
7889

7990
for story in r.stories:
8091
yield await types.Story._parse(
8192
self,
8293
story,
83-
{i.id: i for i in r.users},
84-
{i.id: i for i in r.chats},
94+
users,
95+
chats,
8596
peer
8697
)
8798

pyrogram/types/messages_and_media/story.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ async def _parse(
196196
peer_id = utils.get_input_peer_id(peer)
197197
elif isinstance(peer, raw.types.InputPeerChannel):
198198
peer_id = utils.get_input_peer_id(peer)
199-
r = await client.invoke(raw.functions.channels.GetChannels(id=[peer]))
200-
chats.update({peer_id: r.chats[0]})
199+
if peer_id not in chats:
200+
r = await client.invoke(raw.functions.channels.GetChannels(id=[peer]))
201+
chats.update({peer_id: r.chats[0]})
201202
else:
202203
peer_id = utils.get_raw_peer_id(peer)
203204

0 commit comments

Comments
 (0)