diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index 142fd5d4..b726e364 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -107,6 +107,12 @@ class DialogMethods(UserMethods): req.offset_date = r.messages[-1].date req.offset_peer = entities[utils.get_peer_id(r.dialogs[-1].peer)] + if req.offset_id == r.messages[-1].id: + # In some very rare cases this will get stuck in an infinite + # loop, where the offsets will get reused over and over. If + # the new offset is the same as the one before, break already. + break + req.offset_id = r.messages[-1].id req.exclude_pinned = True