Add a workaround for channels that claim have no photos but do

This commit is contained in:
Lonami Exo 2020-08-13 15:13:29 +02:00
parent e00496aa63
commit 73109eb819

View File

@ -337,9 +337,25 @@ class _ProfilePhotoIter(RequestIter):
else: else:
self.request.offset += len(result.photos) self.request.offset += len(result.photos)
else: else:
self.total = getattr(result, 'count', None)
if self.total == 0 and isinstance(result, types.messages.ChannelMessages):
# There are some broadcast channels that have a photo but this
# request doesn't retrieve it for some reason. Work around this
# issue by fetching the channel.
#
# We can't use the normal entity because that gives `ChatPhoto`
# but we want a proper `Photo`, so fetch full channel instead.
channel = await self.client(functions.channels.GetFullChannelRequest(self.request.peer))
photo = channel.full_chat.chat_photo
if isinstance(photo, types.Photo):
self.buffer = [photo]
self.total = 1
self.left = len(self.buffer)
return
self.buffer = [x.action.photo for x in result.messages self.buffer = [x.action.photo for x in result.messages
if isinstance(x.action, types.MessageActionChatEditPhoto)] if isinstance(x.action, types.MessageActionChatEditPhoto)]
self.total = getattr(result, 'count', None)
if len(result.messages) < self.request.limit: if len(result.messages) < self.request.limit:
self.left = len(self.buffer) self.left = len(self.buffer)
elif result.messages: elif result.messages: