From 4b85ced1e10193812743fff522c15e12d0733a3e Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 23 Jan 2022 19:53:48 +0100 Subject: [PATCH] Reimplement catch_up --- telethon/_client/telegramclient.py | 6 ++---- telethon/_client/updates.py | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index 4504d589..3a39fb28 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -2901,11 +2901,9 @@ class TelegramClient: @forward_call(updates.catch_up) async def catch_up(self: 'TelegramClient'): """ - "Catches up" on the missed updates while the client was offline. - You should call this method after registering the event handlers - so that the updates it loads can by processed by your script. + Forces the client to "catch-up" on missed updates. - This can also be used to forcibly fetch new updates if there are any. + The method does not wait for all updates to be received. Example .. code-block:: python diff --git a/telethon/_client/updates.py b/telethon/_client/updates.py index e3e8fd78..cf26e809 100644 --- a/telethon/_client/updates.py +++ b/telethon/_client/updates.py @@ -80,7 +80,10 @@ def list_event_handlers(self: 'TelegramClient')\ return [(callback, event) for event, callback in self._event_builders] async def catch_up(self: 'TelegramClient'): - pass + # The update loop is probably blocked on either timeout or an update to arrive. + # Unblock the loop by pushing a dummy update which will always trigger a gap. + # This, in return, causes the update loop to catch up. + await self._updates_queue.put(_tl.UpdatesTooLong()) async def _update_loop(self: 'TelegramClient'): try: