Skip to content

Commit

Permalink
Fix messages.search accidentally being used over getHistory
Browse files Browse the repository at this point in the history
Introduced by 668dcd5 (this commit
did change a lot more than it should have); the condition for search
was never updated to account for the non-None value.

Closes #1693.
  • Loading branch information
Lonami committed Feb 8, 2021
1 parent acb066a commit 23041f3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions telethon/client/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ async def _init(

if filter is None:
filter = types.InputMessagesFilterEmpty()
else:
filter = filter() if isinstance(filter, type) else filter

if not self.entity:
self.request = functions.messages.SearchGlobalRequest(
Expand All @@ -94,7 +96,7 @@ async def _init(
min_id=0,
hash=0
)
elif search is not None or filter or from_user:
elif search is not None or not isinstance(filter, types.InputMessagesFilterEmpty) or from_user:

This comment has been minimized.

Copy link
@joell

joell Feb 8, 2021

Wouldn't not isinstance(filter, types.InputMessagesFilterEmpty) always be True if filter == None?

This comment has been minimized.

Copy link
@Lonami

Lonami Feb 8, 2021

Author Member

If filter is None, isinstance will be True, and the not makes it False.

This comment has been minimized.

Copy link
@joell

joell Feb 8, 2021

That's not what I get when I try it in a REPL session. Here's the output:

In [1]: import telethon.tl.types

In [2]: filter = None

In [3]: isinstance(filter, telethon.tl.types.InputMessagesFilterEmpty)
Out[3]: False

In [4]: not isinstance(filter, telethon.tl.types.InputMessagesFilterEmpty)
Out[4]: True

None should only ever be an instance of NoneType or object, so the isinstance call in my REPL session does seem to be providing the correct result.

This comment has been minimized.

Copy link
@joell

joell Feb 8, 2021

Oh! I see now. I misread the condition up on line 71. If filter starts as None it still gets changed to InputMessagesFilterEmpty. You had only added new code to handle if it was non-None.

Sorry to have spent more of your time.

# Telegram completely ignores `from_id` in private chats
ty = helpers._entity_type(self.entity)
if ty == helpers._EntityType.USER:
Expand All @@ -109,7 +111,7 @@ async def _init(
self.request = functions.messages.SearchRequest(
peer=self.entity,
q=search or '',
filter=filter() if isinstance(filter, type) else filter,
filter=filter,
min_date=None,
max_date=offset_date,
offset_id=offset_id,
Expand Down

0 comments on commit 23041f3

Please sign in to comment.