mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-11 00:22:29 +03:00
Stop re-saving input peers on disconnect
This was overwriting actual information on the cache.
This commit is contained in:
parent
b2809e0b57
commit
04922fee3c
|
@ -49,9 +49,6 @@ class EntityCache:
|
||||||
if getattr(c, 'access_hash', None) and not getattr(c, 'min', None)
|
if getattr(c, 'access_hash', None) and not getattr(c, 'min', None)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_all_entities(self):
|
|
||||||
return [Entity(ty, id, hash) for id, (hash, ty) in self.hash_map.items()]
|
|
||||||
|
|
||||||
def put(self, entity):
|
def put(self, entity):
|
||||||
self.hash_map[entity.id] = (entity.hash, entity.ty)
|
self.hash_map[entity.id] = (entity.hash, entity.ty)
|
||||||
|
|
||||||
|
|
|
@ -687,14 +687,10 @@ class TelegramBaseClient(abc.ABC):
|
||||||
connection._proxy = proxy
|
connection._proxy = proxy
|
||||||
|
|
||||||
def _save_states_and_entities(self: 'TelegramClient'):
|
def _save_states_and_entities(self: 'TelegramClient'):
|
||||||
entities = self._mb_entity_cache.get_all_entities()
|
|
||||||
|
|
||||||
# Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities.
|
|
||||||
# It doesn't matter if we put users in the list of chats.
|
|
||||||
self.session.process_entities(types.contacts.ResolvedPeer(None, [e._as_input_peer() for e in entities], []))
|
|
||||||
|
|
||||||
# As a hack to not need to change the session files, save ourselves with ``id=0`` and ``access_hash`` of our ``id``.
|
# As a hack to not need to change the session files, save ourselves with ``id=0`` and ``access_hash`` of our ``id``.
|
||||||
# This way it is possible to determine our own ID by querying for 0. However, whether we're a bot is not saved.
|
# This way it is possible to determine our own ID by querying for 0. However, whether we're a bot is not saved.
|
||||||
|
# Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities.
|
||||||
|
# It doesn't matter if we put users in the list of chats.
|
||||||
if self._mb_entity_cache.self_id:
|
if self._mb_entity_cache.self_id:
|
||||||
self.session.process_entities(types.contacts.ResolvedPeer(None, [types.InputPeerUser(0, self._mb_entity_cache.self_id)], []))
|
self.session.process_entities(types.contacts.ResolvedPeer(None, [types.InputPeerUser(0, self._mb_entity_cache.self_id)], []))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user