mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-28 00:56:19 +00:00
Add basic update handler
This commit is contained in:
parent
315563ede0
commit
fe9b968ad8
@ -81,6 +81,12 @@ class Client:
|
|||||||
self.config = None
|
self.config = None
|
||||||
self.session = None
|
self.session = None
|
||||||
|
|
||||||
|
self.update_handler = None
|
||||||
|
|
||||||
|
# TODO: Better update handler
|
||||||
|
def set_update_handler(self, callback):
|
||||||
|
self.update_handler = callback
|
||||||
|
|
||||||
def send(self, data: Object):
|
def send(self, data: Object):
|
||||||
return self.session.send(data)
|
return self.session.send(data)
|
||||||
|
|
||||||
@ -249,6 +255,7 @@ class Client:
|
|||||||
self.load_session(self.session_name)
|
self.load_session(self.session_name)
|
||||||
|
|
||||||
self.session = Session(self.dc_id, self.test_mode, self.auth_key, self.config.api_id)
|
self.session = Session(self.dc_id, self.test_mode, self.auth_key, self.config.api_id)
|
||||||
|
self.session.update_handler = self.update_handler
|
||||||
|
|
||||||
terms = self.session.start()
|
terms = self.session.start()
|
||||||
|
|
||||||
|
@ -96,6 +96,8 @@ class Session:
|
|||||||
|
|
||||||
self.is_connected = Event()
|
self.is_connected = Event()
|
||||||
|
|
||||||
|
self.update_handler = None
|
||||||
|
|
||||||
self.total_connections = 0
|
self.total_connections = 0
|
||||||
self.total_messages = 0
|
self.total_messages = 0
|
||||||
self.total_bytes = 0
|
self.total_bytes = 0
|
||||||
@ -246,19 +248,22 @@ class Session:
|
|||||||
self.pending_acks.add(i.body.answer_msg_id)
|
self.pending_acks.add(i.body.answer_msg_id)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if isinstance(i.body, types.NewSessionCreated):
|
||||||
|
continue
|
||||||
|
|
||||||
msg_id = None
|
msg_id = None
|
||||||
|
|
||||||
if isinstance(i.body, (types.BadMsgNotification, types.BadServerSalt)):
|
if isinstance(i.body, (types.BadMsgNotification, types.BadServerSalt)):
|
||||||
msg_id = i.body.bad_msg_id
|
msg_id = i.body.bad_msg_id
|
||||||
|
|
||||||
elif isinstance(i.body, types.RpcResult):
|
elif isinstance(i.body, types.RpcResult):
|
||||||
msg_id = i.body.req_msg_id
|
msg_id = i.body.req_msg_id
|
||||||
|
|
||||||
elif isinstance(i.body, types.Pong):
|
elif isinstance(i.body, types.Pong):
|
||||||
msg_id = i.body.msg_id
|
msg_id = i.body.msg_id
|
||||||
|
|
||||||
elif isinstance(i.body, core.FutureSalts):
|
elif isinstance(i.body, core.FutureSalts):
|
||||||
msg_id = i.body.req_msg_id
|
msg_id = i.body.req_msg_id
|
||||||
|
else:
|
||||||
|
if self.update_handler:
|
||||||
|
self.update_handler(i.body)
|
||||||
|
|
||||||
if msg_id in self.results:
|
if msg_id in self.results:
|
||||||
self.results[msg_id].value = getattr(i.body, "result", i.body)
|
self.results[msg_id].value = getattr(i.body, "result", i.body)
|
||||||
|
Loading…
Reference in New Issue
Block a user