diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 77a71537..c508ad52 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -338,9 +338,8 @@ class TelegramClient(TelegramBareClient): break offset_date = r.messages[-1].date - offset_peer = utils.find_user_or_chat( - r.dialogs[-1].peer, entities, entities - ) + offset_peer = entities[ + utils.get_peer_id(r.dialogs[-1].peer, add_mark=True)] offset_id = r.messages[-1].id & 4294967296 # Telegram/danog magic dialogs = UserList(dialogs.values()) diff --git a/telethon/utils.py b/telethon/utils.py index 720345db..531b0dc7 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -386,28 +386,6 @@ def resolve_id(marked_id): return -marked_id, PeerChat -def find_user_or_chat(peer, users, chats): - """Finds the corresponding user or chat given a peer. - Returns None if it was not found""" - if isinstance(peer, PeerUser): - peer, where = peer.user_id, users - else: - where = chats - if isinstance(peer, PeerChat): - peer = peer.chat_id - elif isinstance(peer, PeerChannel): - peer = peer.channel_id - - if isinstance(peer, int): - if isinstance(where, dict): - return where.get(peer) - else: - try: - return next(x for x in where if x.id == peer) - except StopIteration: - pass - - def get_appropriated_part_size(file_size): """Gets the appropriated part size when uploading or downloading files, given an initial file size"""