mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 01:46:35 +03:00
Fix search in private chats when from_user was not given
This commit is contained in:
parent
cf867954c3
commit
8492300780
|
@ -172,13 +172,13 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
else:
|
else:
|
||||||
offset_id = 1
|
offset_id = 1
|
||||||
|
|
||||||
if not from_user:
|
if from_user:
|
||||||
from_id = None
|
from_user = await self.get_input_entity(from_user)
|
||||||
else:
|
if not isinstance(from_user, (
|
||||||
from_id = await self.get_input_entity(from_user)
|
|
||||||
if not isinstance(from_id, (
|
|
||||||
types.InputPeerUser, types.InputPeerSelf)):
|
types.InputPeerUser, types.InputPeerSelf)):
|
||||||
from_id = None # Ignore from_user unless it's a user
|
from_user = None # Ignore from_user unless it's a user
|
||||||
|
|
||||||
|
from_id = (await self.get_peer_id(from_user)) if from_user else None
|
||||||
|
|
||||||
limit = float('inf') if limit is None else int(limit)
|
limit = float('inf') if limit is None else int(limit)
|
||||||
if not entity:
|
if not entity:
|
||||||
|
@ -193,9 +193,20 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
offset_id=offset_id,
|
offset_id=offset_id,
|
||||||
limit=1
|
limit=1
|
||||||
)
|
)
|
||||||
elif search is not None or filter or from_id:
|
elif search is not None or filter or from_user:
|
||||||
if filter is None:
|
if filter is None:
|
||||||
filter = types.InputMessagesFilterEmpty()
|
filter = types.InputMessagesFilterEmpty()
|
||||||
|
|
||||||
|
# Telegram completely ignores `from_id` in private chats
|
||||||
|
if isinstance(entity, (types.InputPeerUser, types.InputPeerSelf)):
|
||||||
|
# Don't bother sending `from_user` (it's ignored anyway),
|
||||||
|
# but keep `from_id` defined above to check it locally.
|
||||||
|
from_user = None
|
||||||
|
else:
|
||||||
|
# Do send `from_user` to do the filtering server-side,
|
||||||
|
# and set `from_id` to None to avoid checking it locally.
|
||||||
|
from_id = None
|
||||||
|
|
||||||
request = functions.messages.SearchRequest(
|
request = functions.messages.SearchRequest(
|
||||||
peer=entity,
|
peer=entity,
|
||||||
q=search or '',
|
q=search or '',
|
||||||
|
@ -208,19 +219,8 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
max_id=0,
|
max_id=0,
|
||||||
min_id=0,
|
min_id=0,
|
||||||
hash=0,
|
hash=0,
|
||||||
from_id=from_id
|
from_id=from_user
|
||||||
)
|
)
|
||||||
|
|
||||||
if not isinstance(entity, (
|
|
||||||
types.InputPeerUser, types.InputPeerSelf)):
|
|
||||||
from_id = None
|
|
||||||
else:
|
|
||||||
# Telegram completely ignores `from_id` in private
|
|
||||||
# chats, so we need to do this check client-side.
|
|
||||||
if isinstance(from_id, types.InputPeerSelf):
|
|
||||||
from_id = await self.get_peer_id('me')
|
|
||||||
else:
|
|
||||||
from_id = from_id.user_id
|
|
||||||
else:
|
else:
|
||||||
request = functions.messages.GetHistoryRequest(
|
request = functions.messages.GetHistoryRequest(
|
||||||
peer=entity,
|
peer=entity,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user