From 70ae7f0808532fa5a02eb5cafc9bbd94679ce8d2 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 19 Mar 2018 01:40:36 +0100 Subject: [PATCH 1/3] Fix usernames not stored in lowercase --- pyrogram/client/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9c49058a..e3968b31 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -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 @@ -889,7 +889,7 @@ class Client: else: raise PeerIdInvalid - self.peers_by_username[username] = input_peer + self.peers_by_username[username.lower()] = input_peer self.peers_by_id[peer_id] = input_peer return input_peer From 9e386ed24c54eb0b017d5b13a4282592b92be530 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 19 Mar 2018 01:51:47 +0100 Subject: [PATCH 2/3] Remove resolve_username method --- pyrogram/client/client.py | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e3968b31..57706657 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -865,35 +865,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.lower()] = 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*. @@ -934,7 +905,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] From 0f2dc6c62442eacee841759ccd2413ceef97a795 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 19 Mar 2018 01:53:07 +0100 Subject: [PATCH 3/3] Remove unnecessary method calls --- pyrogram/client/client.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 57706657..736092b9 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -639,9 +639,6 @@ class Client: ) ) - self.fetch_peers(diff.users) - self.fetch_peers(diff.chats) - self.update_queue.put(( types.UpdateNewMessage( message=diff.new_messages[0],