Fix _get_peer was relying on old utils.resolve_id

This commit is contained in:
Lonami Exo 2021-09-19 17:21:11 +02:00
parent 9479e215fb
commit d60ebbe6ea
3 changed files with 10 additions and 9 deletions

View File

@ -293,7 +293,7 @@ class _IDsIter(requestiter.RequestIter):
else:
r = await self.client(_tl.fn.messages.GetMessages(ids))
if self._entity:
from_id = await self.client._get_peer(self._entity)
from_id = await _get_peer(self.client, self._entity)
if isinstance(r, _tl.messages.MessagesNotModified):
self.buffer.extend(None for _ in ids)
@ -318,6 +318,14 @@ class _IDsIter(requestiter.RequestIter):
self.buffer.append(_custom.Message._new(self.client, message, entities, self._entity))
async def _get_peer(self: 'TelegramClient', input_peer: 'hints.EntityLike'):
try:
return utils.get_peer(input_peer)
except TypeError:
# Can only be self by now
return _tl.PeerUser(await self.get_peer_id(input_peer))
def get_messages(
self: 'TelegramClient',
entity: 'hints.EntityLike',
@ -480,7 +488,7 @@ async def send_message(
if isinstance(result, _tl.UpdateShortSentMessage):
return _custom.Message._new(self, _tl.Message(
id=result.id,
peer_id=await self._get_peer(entity),
peer_id=await _get_peer(self, entity),
message=message,
date=result.date,
out=result.out,

View File

@ -3573,9 +3573,6 @@ class TelegramClient:
ttl=None):
return await uploads._file_to_media(**locals())
async def _get_peer(self: 'TelegramClient', peer: 'hints.EntityLike'):
return await users._get_peer(**locals())
def _get_response_message(self: 'TelegramClient', request, result, input_chat):
return messageparse._get_response_message(**locals())

View File

@ -323,10 +323,6 @@ async def get_input_entity(
.format(peer, type(peer).__name__)
)
async def _get_peer(self: 'TelegramClient', peer: 'hints.EntityLike'):
i, cls = utils.resolve_id(await self.get_peer_id(peer))
return cls(i)
async def get_peer_id(
self: 'TelegramClient',
peer: 'hints.EntityLike') -> int: