diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e93e3ff8..2ba6b8fa 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -765,7 +765,9 @@ class Client(Methods, BaseClient): types.Channel, types.ChannelForbidden ] ] - ): + ) -> bool: + is_min = False + for entity in entities: if isinstance(entity, types.User): user_id = entity.id @@ -773,6 +775,7 @@ class Client(Methods, BaseClient): access_hash = entity.access_hash if access_hash is None: + is_min = True continue username = entity.username @@ -808,6 +811,7 @@ class Client(Methods, BaseClient): access_hash = entity.access_hash if access_hash is None: + is_min = True continue username = getattr(entity, "username", None) @@ -822,6 +826,8 @@ class Client(Methods, BaseClient): if username is not None: self.peers_by_username[username.lower()] = input_peer + return is_min + def download_worker(self): name = threading.current_thread().name log.debug("{} started".format(name)) @@ -837,7 +843,6 @@ class Client(Methods, BaseClient): try: data, file_name, done, progress, progress_args, path = packet - data = data # type: BaseClient.FileData directory, file_name = os.path.split(file_name) directory = directory or "downloads" @@ -917,8 +922,10 @@ class Client(Methods, BaseClient): try: if isinstance(updates, (types.Update, types.UpdatesCombined)): - self.fetch_peers(updates.users) - self.fetch_peers(updates.chats) + is_min = self.fetch_peers(updates.users) or self.fetch_peers(updates.chats) + + users = {u.id: u for u in updates.users} + chats = {c.id: c for c in updates.chats} for update in updates.updates: channel_id = getattr( @@ -935,7 +942,7 @@ class Client(Methods, BaseClient): if isinstance(update, types.UpdateChannelTooLong): log.warning(update) - if isinstance(update, types.UpdateNewChannelMessage): + if isinstance(update, types.UpdateNewChannelMessage) and is_min: message = update.message if not isinstance(message, types.MessageEmpty): @@ -957,22 +964,10 @@ class Client(Methods, BaseClient): pass else: if not isinstance(diff, types.updates.ChannelDifferenceEmpty): - updates.users += diff.users - updates.chats += diff.chats + users.update({u.id: u for u in diff.users}) + chats.update({c.id: c for c in diff.chats}) - if channel_id and pts: - if channel_id not in self.channels_pts: - self.channels_pts[channel_id] = [] - - if pts in self.channels_pts[channel_id]: - continue - - self.channels_pts[channel_id].append(pts) - - if len(self.channels_pts[channel_id]) > 50: - self.channels_pts[channel_id] = self.channels_pts[channel_id][25:] - - self.dispatcher.updates_queue.put((update, updates.users, updates.chats)) + self.dispatcher.updates_queue.put((update, users, chats)) elif isinstance(updates, (types.UpdateShortMessage, types.UpdateShortChatMessage)): diff = self.send( functions.updates.GetDifference( @@ -989,13 +984,13 @@ class Client(Methods, BaseClient): pts=updates.pts, pts_count=updates.pts_count ), - diff.users, - diff.chats + {u.id: u for u in diff.users}, + {c.id: c for c in diff.chats} )) else: - self.dispatcher.updates_queue.put((diff.other_updates[0], [], [])) + self.dispatcher.updates_queue.put((diff.other_updates[0], {}, {})) elif isinstance(updates, types.UpdateShort): - self.dispatcher.updates_queue.put((updates.update, [], [])) + self.dispatcher.updates_queue.put((updates.update, {}, {})) elif isinstance(updates, types.UpdatesTooLong): log.warning(updates) except Exception as e: diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index b193ceee..9c0d661e 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -96,7 +96,6 @@ class BaseClient: self.date = None self.rnd_id = MsgId - self.channels_pts = {} self.peers_by_id = {} self.peers_by_username = {} diff --git a/pyrogram/client/ext/dispatcher.py b/pyrogram/client/ext/dispatcher.py index 1004095b..2f1ec2b9 100644 --- a/pyrogram/client/ext/dispatcher.py +++ b/pyrogram/client/ext/dispatcher.py @@ -125,16 +125,13 @@ class Dispatcher: log.debug("{} started".format(name)) while True: - update = self.updates_queue.get() + packet = self.updates_queue.get() - if update is None: + if packet is None: break try: - users = {i.id: i for i in update[1]} - chats = {i.id: i for i in update[2]} - update = update[0] - + update, users, chats = packet parser = self.update_parsers.get(type(update), None) parsed_update, handler_type = (