Merge branch 'master' into min

This commit is contained in:
Dan 2018-03-19 01:53:59 +01:00
commit eecc9412b5

View File

@ -455,7 +455,7 @@ class Client:
self.peers_by_id[user_id] = input_peer
if username is not None:
self.peers_by_username[username] = input_peer
self.peers_by_username[username.lower()] = input_peer
if phone is not None:
self.peers_by_phone[phone] = input_peer
@ -495,7 +495,7 @@ class Client:
self.peers_by_id[peer_id] = input_peer
if username is not None:
self.peers_by_username[username] = input_peer
self.peers_by_username[username.lower()] = input_peer
def download_worker(self):
name = threading.current_thread().name
@ -661,9 +661,6 @@ class Client:
)
)
self.fetch_peers(diff.users)
self.fetch_peers(diff.chats)
self.update_queue.put((
types.UpdateNewMessage(
message=diff.new_messages[0],
@ -887,35 +884,6 @@ class Client:
offset_date = parse_dialogs(dialogs)
log.info("Entities count: {}".format(len(self.peers_by_id)))
def resolve_username(self, username: str):
username = username.lower().strip("@")
resolved_peer = self.send(
functions.contacts.ResolveUsername(
username=username
)
) # type: types.contacts.ResolvedPeer
if type(resolved_peer.peer) is PeerUser:
input_peer = InputPeerUser(
user_id=resolved_peer.users[0].id,
access_hash=resolved_peer.users[0].access_hash
)
peer_id = input_peer.user_id
elif type(resolved_peer.peer) is PeerChannel:
input_peer = InputPeerChannel(
channel_id=resolved_peer.chats[0].id,
access_hash=resolved_peer.chats[0].access_hash
)
peer_id = int("-100" + str(input_peer.channel_id))
else:
raise PeerIdInvalid
self.peers_by_username[username] = input_peer
self.peers_by_id[peer_id] = input_peer
return input_peer
def resolve_peer(self, peer_id: int or str):
"""Use this method to get the *InputPeer* of a known *peer_id*.
@ -956,7 +924,8 @@ class Client:
try:
return self.peers_by_username[peer_id]
except KeyError:
return self.resolve_username(peer_id)
self.send(functions.contacts.ResolveUsername(peer_id))
return self.peers_by_username[peer_id]
else:
try:
return self.peers_by_phone[peer_id]