Skip to content

Commit ce150d9

Browse files
anonymousx97SpEcHiDe
authored andcommitted
fix: drop unnecessary high level parsing of messages in get_chat_photo (#203)
1 parent 210d92c commit ce150d9

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

pyrogram/methods/users/get_chat_photos.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import Union, AsyncGenerator, Optional
2121

2222
import pyrogram
23-
from pyrogram import types, raw, utils
23+
from pyrogram import types, raw
2424

2525

2626
class GetChatPhotos:
@@ -70,37 +70,37 @@ async def get_chat_photos(
7070
chat_icons = [_animation or _photo]
7171

7272
if not (self.me and self.me.is_bot):
73-
r = await utils.parse_messages(
74-
self,
75-
await self.invoke(
76-
raw.functions.messages.Search(
77-
peer=peer_id,
78-
q="",
79-
filter=raw.types.InputMessagesFilterChatPhotos(),
80-
min_date=0,
81-
max_date=0,
82-
offset_id=0,
83-
add_offset=0,
84-
limit=limit,
85-
max_id=0,
86-
min_id=0,
87-
hash=0,
88-
)
89-
),
73+
r = await self.invoke(
74+
raw.functions.messages.Search(
75+
peer=peer_id,
76+
q="",
77+
filter=raw.types.InputMessagesFilterChatPhotos(),
78+
min_date=0,
79+
max_date=0,
80+
offset_id=0,
81+
add_offset=0,
82+
limit=limit,
83+
max_id=0,
84+
min_id=0,
85+
hash=0,
86+
)
9087
)
9188
if _icon := chat_icons[0]:
9289
_first_file_id = _icon.file_id if _animation else _icon.sizes[0].file_id
9390
else:
9491
_first_file_id = None
95-
for m in r:
96-
if isinstance(m.new_chat_photo, types.Animation):
97-
_current_file_id = m.new_chat_photo.file_id
98-
elif isinstance(m.new_chat_photo, types.Photo):
99-
_current_file_id = m.new_chat_photo.sizes[0].file_id
100-
else:
92+
93+
for m in getattr(r, "messages", []):
94+
if not isinstance(getattr(m, "action", None), raw.types.MessageActionChatEditPhoto):
10195
continue
102-
if _first_file_id != _current_file_id:
103-
chat_icons.append(m.new_chat_photo)
96+
97+
_c_animation = types.Animation._parse_chat_animation(self, m.action.photo)
98+
_c_photo = types.Photo._parse(self, m.action.photo)
99+
100+
_current_file_id = (_c_animation and _c_animation.file_id) or (_c_photo and _c_photo.sizes[0].file_id)
101+
102+
if (_c_animation or _c_photo) and _first_file_id != _current_file_id:
103+
chat_icons.append(_c_animation or _c_photo)
104104

105105
current = 0
106106

0 commit comments

Comments
 (0)