diff --git a/telethon/_updates/messagebox.py b/telethon/_updates/messagebox.py index 72081eb9..e5f67f93 100644 --- a/telethon/_updates/messagebox.py +++ b/telethon/_updates/messagebox.py @@ -572,8 +572,14 @@ class MessageBox: if pts.entry in self.map: self.map[pts.entry].pts = pts.pts else: + # When a chat is migrated to a megagroup, the first update can be a `ReadChannelInbox` + # with `pts = 1, pts_count = 0` followed by a `NewChannelMessage` with `pts = 2, pts_count=1`. + # Note how the `pts` for the message is 2 and not 1 unlike the case described before! + # This is likely because the `pts` cannot be 0 (or it would fail with PERSISTENT_TIMESTAMP_EMPTY), + # which forces the first update to be 1. But if we got difference with 1 and the second update + # also used 1, we would miss it, so Telegram probably uses 2 to work around that. self.map[pts.entry] = State( - pts=pts.pts - (0 if pts.pts_count else 1), + pts=(pts.pts - (0 if pts.pts_count else 1)) or 1, deadline=next_updates_deadline() )