Guess entity type on positive IDs in events and avoid some RPCs

Now specifying a single positive integer ID will add all the types
to the white/blacklist so it can be "guessed". Explicit peers will
always be only that type, and an RPC is avoided  (since it was not
needed to begin with).
This commit is contained in:
Lonami Exo 2018-03-24 18:34:07 +01:00
parent 13e59983af
commit 790b0d2d23

View File

@ -20,10 +20,24 @@ def _into_id_set(client, chats):
result = set() result = set()
for chat in chats: for chat in chats:
chat = client.get_input_entity(chat) if isinstance(chat, int):
if isinstance(chat, types.InputPeerSelf): if chat < 0:
chat = client.get_me(input_peer=True) result.add(chat) # Explicitly marked IDs are negative
result.add(utils.get_peer_id(chat)) else:
result.update({ # Support all valid types of peers
utils.get_peer_id(types.PeerUser(chat)),
utils.get_peer_id(types.PeerChat(chat)),
utils.get_peer_id(types.PeerChannel(chat)),
})
elif isinstance(chat, TLObject) and chat.SUBCLASS_OF_ID == 0x2d45687:
# 0x2d45687 == crc32(b'Peer')
result.add(utils.get_peer_id(chat))
else:
chat = client.get_input_entity(chat)
if isinstance(chat, types.InputPeerSelf):
chat = client.get_me(input_peer=True)
result.add(utils.get_peer_id(chat))
return result return result