mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 21:10:29 +00:00
Add basic updates processing to ignore updates with lower .pts
This commit is contained in:
@@ -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"""
|
||||
|
Reference in New Issue
Block a user