Fix EntityDatabase failing to cache self user

This commit is contained in:
Lonami Exo 2017-10-05 13:14:54 +02:00
parent 4f2a44231a
commit 1fb3d0d00c
2 changed files with 5 additions and 5 deletions

View File

@ -66,7 +66,7 @@ class EntityDatabase:
continue continue
try: try:
p = utils.get_input_peer(e) p = utils.get_input_peer(e, allow_self=False)
new_input[utils.get_peer_id(p, add_mark=True)] = \ new_input[utils.get_peer_id(p, add_mark=True)] = \
getattr(p, 'access_hash', 0) # chats won't have hash getattr(p, 'access_hash', 0) # chats won't have hash
@ -93,7 +93,7 @@ class EntityDatabase:
"full" means simply not "Input*". "full" means simply not "Input*".
""" """
marked_id = utils.get_peer_id( marked_id = utils.get_peer_id(
utils.get_input_peer(entity), add_mark=True utils.get_input_peer(entity, allow_self=False), add_mark=True
) )
try: try:
old_entity = self._entities[marked_id] old_entity = self._entities[marked_id]

View File

@ -72,7 +72,7 @@ def _raise_cast_fail(entity, target):
.format(type(entity).__name__, target)) .format(type(entity).__name__, target))
def get_input_peer(entity): def get_input_peer(entity, allow_self=True):
"""Gets the input peer for the given "entity" (user, chat or channel). """Gets the input peer for the given "entity" (user, chat or channel).
A ValueError is raised if the given entity isn't a supported type.""" A ValueError is raised if the given entity isn't a supported type."""
if not isinstance(entity, TLObject): if not isinstance(entity, TLObject):
@ -82,7 +82,7 @@ def get_input_peer(entity):
return entity return entity
if isinstance(entity, User): if isinstance(entity, User):
if entity.is_self: if entity.is_self and allow_self:
return InputPeerSelf() return InputPeerSelf()
else: else:
return InputPeerUser(entity.id, entity.access_hash) return InputPeerUser(entity.id, entity.access_hash)
@ -312,7 +312,7 @@ def get_peer_id(peer, add_mark=False):
if type(peer).SUBCLASS_OF_ID not in {0x2d45687, 0xc91c90b6}: if type(peer).SUBCLASS_OF_ID not in {0x2d45687, 0xc91c90b6}:
# Not a Peer or an InputPeer, so first get its Input version # Not a Peer or an InputPeer, so first get its Input version
peer = get_input_peer(peer) peer = get_input_peer(peer, allow_self=False)
if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser): if isinstance(peer, PeerUser) or isinstance(peer, InputPeerUser):
return peer.user_id return peer.user_id