From 9c87598950a71124432f5efb7e13a83a533999c9 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 13 Nov 2020 10:59:25 +0100 Subject: [PATCH] Don't include *Empty entities in returned dialogs --- telethon/client/dialogs.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index bced1cd7..c700319a 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -55,7 +55,8 @@ class _DialogsIter(RequestIter): self.total = getattr(r, 'count', len(r.dialogs)) entities = {utils.get_peer_id(x): x - for x in itertools.chain(r.users, r.chats)} + for x in itertools.chain(r.users, r.chats) + if not isinstance(x, (types.UserEmpty, types.ChatEmpty))} messages = {} for m in r.messages: @@ -73,6 +74,12 @@ class _DialogsIter(RequestIter): peer_id = utils.get_peer_id(d.peer) if peer_id not in self.seen: self.seen.add(peer_id) + if peer_id not in entities: + # > In which case can a UserEmpty appear in the list of banned members? + # > In a very rare cases. This is possible but isn't an expected behavior. + # Real world example: https://t.me/TelethonChat/271471 + continue + cd = custom.Dialog(self.client, d, entities, message) if cd.dialog.pts: self.client._channel_pts[cd.id] = cd.dialog.pts @@ -99,8 +106,7 @@ class _DialogsIter(RequestIter): self.request.exclude_pinned = True self.request.offset_id = last_message.id if last_message else 0 self.request.offset_date = last_message.date if last_message else None - self.request.offset_peer =\ - entities[utils.get_peer_id(r.dialogs[-1].peer)] + self.request.offset_peer = self.buffer[-1].input_entity class _DraftsIter(RequestIter):