Add basic updates processing to ignore updates with lower .pts

This commit is contained in:
Lonami Exo
2017-09-07 20:17:40 +02:00
parent d237375208
commit b8e881b6b6
3 changed files with 34 additions and 9 deletions

View File

@@ -1,8 +1,8 @@
import os
import threading
from datetime import datetime, timedelta
from mimetypes import guess_type
from threading import RLock, Thread
import threading
from . import TelegramBareClient
from . import helpers as utils
@@ -27,6 +27,9 @@ from .tl.functions.messages import (
GetDialogsRequest, GetHistoryRequest, ReadHistoryRequest, SendMediaRequest,
SendMessageRequest
)
from .tl.functions.updates import (
GetStateRequest
)
from .tl.functions.users import (
GetUsersRequest
)
@@ -155,6 +158,8 @@ class TelegramClient(TelegramBareClient):
target=self._recv_thread_impl
)
self._recv_thread.start()
if self.updates.enabled:
self.sync_updates()
return ok
@@ -904,6 +909,13 @@ class TelegramClient(TelegramBareClient):
# region Updates handling
def sync_updates(self):
"""Synchronizes self.updates to their initial state. Will be
called automatically on connection if self.updates.enabled = True,
otherwise it should be called manually after enabling updates.
"""
self.updates.process(self(GetStateRequest()))
def add_update_handler(self, handler):
"""Adds an update handler (a function which takes a TLObject,
an update, as its parameter) and listens for updates"""