mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 09:53:45 +03:00
Update in-memory updates.State
This commit is contained in:
parent
4ab5c7d92d
commit
a1477a84bf
|
@ -92,6 +92,9 @@ class DialogMethods(UserMethods):
|
||||||
if peer_id not in seen:
|
if peer_id not in seen:
|
||||||
seen.add(peer_id)
|
seen.add(peer_id)
|
||||||
cd = custom.Dialog(self, d, entities, messages)
|
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(
|
if not ignore_migrated or getattr(
|
||||||
cd.entity, 'migrated_to', None) is None:
|
cd.entity, 'migrated_to', None) is None:
|
||||||
await yield_(cd)
|
await yield_(cd)
|
||||||
|
|
|
@ -13,7 +13,7 @@ from ..extensions import markdown
|
||||||
from ..network import MTProtoSender, ConnectionTcpFull
|
from ..network import MTProtoSender, ConnectionTcpFull
|
||||||
from ..network.mtprotostate import MTProtoState
|
from ..network.mtprotostate import MTProtoState
|
||||||
from ..sessions import Session, SQLiteSession
|
from ..sessions import Session, SQLiteSession
|
||||||
from ..tl import TLObject, functions
|
from ..tl import TLObject, functions, types
|
||||||
from ..tl.alltlobjects import LAYER
|
from ..tl.alltlobjects import LAYER
|
||||||
|
|
||||||
DEFAULT_DC_ID = 4
|
DEFAULT_DC_ID = 4
|
||||||
|
@ -219,9 +219,10 @@ class TelegramBaseClient(abc.ABC):
|
||||||
self._last_ping = datetime.now()
|
self._last_ping = datetime.now()
|
||||||
self._ping_delay = timedelta(minutes=1)
|
self._ping_delay = timedelta(minutes=1)
|
||||||
|
|
||||||
self._state = None
|
|
||||||
self._updates_handle = None
|
self._updates_handle = None
|
||||||
self._last_request = time.time()
|
self._last_request = time.time()
|
||||||
|
self._channel_pts = {}
|
||||||
|
self._state = types.updates.State(0, 0, datetime.now(), 0, -1)
|
||||||
|
|
||||||
# Some further state for subclasses
|
# Some further state for subclasses
|
||||||
self._event_builders = []
|
self._event_builders = []
|
||||||
|
|
|
@ -175,13 +175,25 @@ class UpdateMethods(UserMethods):
|
||||||
itertools.chain(update.users, update.chats)}
|
itertools.chain(update.users, update.chats)}
|
||||||
for u in update.updates:
|
for u in update.updates:
|
||||||
u._entities = entities
|
u._entities = entities
|
||||||
self._loop.create_task(self._dispatch_update(u))
|
self._handle_update(u)
|
||||||
return
|
|
||||||
if isinstance(update, types.UpdateShort):
|
if isinstance(update, types.UpdateShort):
|
||||||
update = update.update
|
self._handle_update(update.update)
|
||||||
update._entities = {}
|
else:
|
||||||
|
update._entities = getattr(update, '_entities', {})
|
||||||
self._loop.create_task(self._dispatch_update(update))
|
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):
|
async def _update_loop(self):
|
||||||
# Pings' ID don't really need to be secure, just "random"
|
# Pings' ID don't really need to be secure, just "random"
|
||||||
rnd = lambda: random.randrange(-2**63, 2**63)
|
rnd = lambda: random.randrange(-2**63, 2**63)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user