mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 19:00:21 +03:00
Look in all dialogs when getting entities by peer ID
This commit is contained in:
parent
771c573db1
commit
3a3f221bd1
|
@ -572,7 +572,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
|
|
||||||
offset_date = r.messages[-1].date
|
offset_date = r.messages[-1].date
|
||||||
offset_peer = entities[utils.get_peer_id(r.dialogs[-1].peer)]
|
offset_peer = entities[utils.get_peer_id(r.dialogs[-1].peer)]
|
||||||
offset_id = r.messages[-1].id & 4294967296 # Telegram/danog magic
|
offset_id = r.messages[-1].id
|
||||||
|
|
||||||
dialogs = UserList(
|
dialogs = UserList(
|
||||||
itertools.islice(dialogs.values(), min(limit, len(dialogs)))
|
itertools.islice(dialogs.values(), min(limit, len(dialogs)))
|
||||||
|
@ -2175,22 +2175,32 @@ class TelegramClient(TelegramBareClient):
|
||||||
'Cannot turn "{}" into an input entity.'.format(peer)
|
'Cannot turn "{}" into an input entity.'.format(peer)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Not found, look in the latest dialogs.
|
# Not found, look in the dialogs with the hope to find it.
|
||||||
# This is useful if for instance someone just sent a message but
|
target_id = utils.get_peer_id(peer)
|
||||||
# the updates didn't specify who, as this person or chat should
|
req = GetDialogsRequest(
|
||||||
# be in the latest dialogs.
|
|
||||||
dialogs = self(GetDialogsRequest(
|
|
||||||
offset_date=None,
|
offset_date=None,
|
||||||
offset_id=0,
|
offset_id=0,
|
||||||
offset_peer=InputPeerEmpty(),
|
offset_peer=InputPeerEmpty(),
|
||||||
limit=0,
|
limit=100
|
||||||
exclude_pinned=True
|
)
|
||||||
))
|
while True:
|
||||||
|
result = self(req)
|
||||||
|
entities = {}
|
||||||
|
for x in itertools.chain(result.users, result.chats):
|
||||||
|
x_id = utils.get_peer_id(x)
|
||||||
|
if x_id == target_id:
|
||||||
|
return utils.get_input_peer(x)
|
||||||
|
else:
|
||||||
|
entities[x_id] = x
|
||||||
|
if len(result.dialogs) < req.limit:
|
||||||
|
break
|
||||||
|
|
||||||
target = utils.get_peer_id(peer)
|
req.offset_id = result.messages[-1].id
|
||||||
for entity in itertools.chain(dialogs.users, dialogs.chats):
|
req.offset_date = result.messages[-1].date
|
||||||
if utils.get_peer_id(entity) == target:
|
req.offset_peer = entities[utils.get_peer_id(
|
||||||
return utils.get_input_peer(entity)
|
result.dialogs[-1].peer
|
||||||
|
)]
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
'Could not find the input entity corresponding to "{}". '
|
'Could not find the input entity corresponding to "{}". '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user