mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-10 16:40:57 +03:00
Process entities from the MtProtoSender instead TelegramBareClient
This way, update objects will also be processed when they occur.
This commit is contained in:
parent
71b6e527a6
commit
36dabc4928
|
@ -213,14 +213,8 @@ class MtProtoSender:
|
||||||
# If the code is not parsed manually then it should be a TLObject.
|
# If the code is not parsed manually then it should be a TLObject.
|
||||||
if code in tlobjects:
|
if code in tlobjects:
|
||||||
result = reader.tgread_object()
|
result = reader.tgread_object()
|
||||||
if state is None:
|
self.session.process_entities(result)
|
||||||
self._logger.debug(
|
if state:
|
||||||
'Ignoring unhandled TLObject %s', repr(result)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._logger.debug(
|
|
||||||
'Processing TLObject %s', repr(result)
|
|
||||||
)
|
|
||||||
state.process(result)
|
state.process(result)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -364,6 +358,7 @@ class MtProtoSender:
|
||||||
reader.seek(-4)
|
reader.seek(-4)
|
||||||
request.on_response(reader)
|
request.on_response(reader)
|
||||||
|
|
||||||
|
self.session.process_entities(request.result)
|
||||||
request.confirm_received.set()
|
request.confirm_received.set()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -494,21 +494,10 @@ class TelegramBareClient:
|
||||||
# rejected by the other party as a whole."
|
# rejected by the other party as a whole."
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Save all input entities we know of
|
if len(requests) == 1:
|
||||||
entities = []
|
return requests[0].result
|
||||||
results = []
|
else:
|
||||||
for x in requests:
|
return [x.result for x in requests]
|
||||||
y = x.result
|
|
||||||
results.append(y)
|
|
||||||
if hasattr(y, 'chats') and hasattr(y.chats, '__iter__'):
|
|
||||||
entities.extend(y.chats)
|
|
||||||
if hasattr(y, 'users') and hasattr(y.users, '__iter__'):
|
|
||||||
entities.extend(y.users)
|
|
||||||
|
|
||||||
if self.session.add_entities(entities):
|
|
||||||
self.session.save() # Save if any new entities got added
|
|
||||||
|
|
||||||
return results[0] if len(results) == 1 else results
|
|
||||||
|
|
||||||
except (PhoneMigrateError, NetworkMigrateError,
|
except (PhoneMigrateError, NetworkMigrateError,
|
||||||
UserMigrateError) as e:
|
UserMigrateError) as e:
|
||||||
|
|
|
@ -185,11 +185,28 @@ class Session:
|
||||||
correct = correct_msg_id >> 32
|
correct = correct_msg_id >> 32
|
||||||
self.time_offset = correct - now
|
self.time_offset = correct - now
|
||||||
|
|
||||||
|
def process_entities(self, tlobject):
|
||||||
|
"""Processes all the found entities on the given TLObject,
|
||||||
|
unless .save_entities is False, and saves the session file.
|
||||||
|
"""
|
||||||
|
if not self.save_entities:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Save all input entities we know of
|
||||||
|
entities = []
|
||||||
|
if hasattr(tlobject, 'chats') and hasattr(tlobject.chats, '__iter__'):
|
||||||
|
entities.extend(tlobject.chats)
|
||||||
|
if hasattr(tlobject, 'users') and hasattr(tlobject.users, '__iter__'):
|
||||||
|
entities.extend(tlobject.users)
|
||||||
|
|
||||||
|
if self.add_entities(entities):
|
||||||
|
self.save() # Save if any new entities got added
|
||||||
|
|
||||||
def add_entities(self, entities):
|
def add_entities(self, entities):
|
||||||
"""Adds new input entities to the local database of them.
|
"""Adds new input entities to the local database unconditionally.
|
||||||
Unknown types will be ignored.
|
Unknown types will be ignored.
|
||||||
"""
|
"""
|
||||||
if not entities or not self.save_entities:
|
if not entities:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
new = {}
|
new = {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user