diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index 6a34bf99..142fd5d4 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -92,6 +92,9 @@ class DialogMethods(UserMethods): if peer_id not in seen: seen.add(peer_id) cd = custom.Dialog(self, d, entities, messages) + if cd.dialog.pts: + self._channel_pts[cd.id] = cd.dialog.pts + if not ignore_migrated or getattr( cd.entity, 'migrated_to', None) is None: await yield_(cd) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 0c582659..986ee7ba 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -13,7 +13,7 @@ from ..extensions import markdown from ..network import MTProtoSender, ConnectionTcpFull from ..network.mtprotostate import MTProtoState from ..sessions import Session, SQLiteSession -from ..tl import TLObject, functions +from ..tl import TLObject, functions, types from ..tl.alltlobjects import LAYER DEFAULT_DC_ID = 4 @@ -219,9 +219,10 @@ class TelegramBaseClient(abc.ABC): self._last_ping = datetime.now() self._ping_delay = timedelta(minutes=1) - self._state = None self._updates_handle = None self._last_request = time.time() + self._channel_pts = {} + self._state = types.updates.State(0, 0, datetime.now(), 0, -1) # Some further state for subclasses self._event_builders = [] diff --git a/telethon/client/updates.py b/telethon/client/updates.py index 2fbb13e0..9fbb4ce2 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -175,12 +175,24 @@ class UpdateMethods(UserMethods): itertools.chain(update.users, update.chats)} for u in update.updates: u._entities = entities - self._loop.create_task(self._dispatch_update(u)) - return + self._handle_update(u) if isinstance(update, types.UpdateShort): - update = update.update - update._entities = {} - self._loop.create_task(self._dispatch_update(update)) + self._handle_update(update.update) + else: + update._entities = getattr(update, '_entities', {}) + self._loop.create_task(self._dispatch_update(update)) + + need_diff = False + if hasattr(update, 'pts'): + if self._state.pts and (update.pts - self._state.pts) > 1: + need_diff = True + self._state.pts = update.pts + if hasattr(update, 'date'): + self._state.date = update.date + if hasattr(update, 'seq'): + self._state.seq = update.seq + + # TODO make use of need_diff async def _update_loop(self): # Pings' ID don't really need to be secure, just "random"