mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 01:46:35 +03:00
Replace custom.Message creation with ._finish_init
This commit is contained in:
parent
61a9f1e61c
commit
1c0d595205
|
@ -80,10 +80,14 @@ class DialogMethods(UserMethods):
|
||||||
|
|
||||||
if _total:
|
if _total:
|
||||||
_total[0] = getattr(r, 'count', len(r.dialogs))
|
_total[0] = getattr(r, 'count', len(r.dialogs))
|
||||||
|
|
||||||
entities = {utils.get_peer_id(x): x
|
entities = {utils.get_peer_id(x): x
|
||||||
for x in itertools.chain(r.users, r.chats)}
|
for x in itertools.chain(r.users, r.chats)}
|
||||||
messages = {m.id: custom.Message(self, m, entities, None)
|
|
||||||
for m in r.messages}
|
messages = {}
|
||||||
|
for m in r.messages:
|
||||||
|
m._finish_init(self, entities, None)
|
||||||
|
messages[m.id] = m
|
||||||
|
|
||||||
# Happens when there are pinned dialogs
|
# Happens when there are pinned dialogs
|
||||||
if len(r.dialogs) > limit:
|
if len(r.dialogs) > limit:
|
||||||
|
|
|
@ -133,6 +133,7 @@ class MessageParseMethods(UserMethods):
|
||||||
break
|
break
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
return custom.Message(self, found, entities, input_chat)
|
found._finish_init(self, entities, input_chat)
|
||||||
|
return found
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
|
@ -256,7 +256,8 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
# IDs are returned in descending order (or asc if reverse).
|
# IDs are returned in descending order (or asc if reverse).
|
||||||
last_id = message.id
|
last_id = message.id
|
||||||
|
|
||||||
await yield_(custom.Message(self, message, entities, entity))
|
message._finish_init(self, entities, entity)
|
||||||
|
await yield_(message)
|
||||||
have += 1
|
have += 1
|
||||||
|
|
||||||
if len(r.messages) < request.limit:
|
if len(r.messages) < request.limit:
|
||||||
|
@ -469,7 +470,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
result = await self(request)
|
result = await self(request)
|
||||||
if isinstance(result, types.UpdateShortSentMessage):
|
if isinstance(result, types.UpdateShortSentMessage):
|
||||||
to_id, cls = utils.resolve_id(utils.get_peer_id(entity))
|
to_id, cls = utils.resolve_id(utils.get_peer_id(entity))
|
||||||
return custom.Message(self, types.Message(
|
message = types.Message(
|
||||||
id=result.id,
|
id=result.id,
|
||||||
to_id=cls(to_id),
|
to_id=cls(to_id),
|
||||||
message=message,
|
message=message,
|
||||||
|
@ -477,7 +478,9 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
out=result.out,
|
out=result.out,
|
||||||
media=result.media,
|
media=result.media,
|
||||||
entities=result.entities
|
entities=result.entities
|
||||||
), {}, input_chat=entity)
|
)
|
||||||
|
message._finish_init(self, {}, entity)
|
||||||
|
return message
|
||||||
|
|
||||||
return self._get_response_message(request, result, entity)
|
return self._get_response_message(request, result, entity)
|
||||||
|
|
||||||
|
@ -547,8 +550,8 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
random_to_id[update.random_id] = update.id
|
random_to_id[update.random_id] = update.id
|
||||||
elif isinstance(update, (
|
elif isinstance(update, (
|
||||||
types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
types.UpdateNewMessage, types.UpdateNewChannelMessage)):
|
||||||
id_to_message[update.message.id] = custom.Message(
|
update.message._finish_init(self, entities, entity)
|
||||||
self, update.message, entities, input_chat=entity)
|
id_to_message[update.message.id] = update.message
|
||||||
|
|
||||||
result = [id_to_message[random_to_id[rnd]] for rnd in req.random_id]
|
result = [id_to_message[random_to_id[rnd]] for rnd in req.random_id]
|
||||||
return result[0] if single else result
|
return result[0] if single else result
|
||||||
|
@ -774,6 +777,7 @@ class MessageMethods(UploadMethods, ButtonMethods, MessageParseMethods):
|
||||||
from_id and utils.get_peer_id(message.to_id) != from_id):
|
from_id and utils.get_peer_id(message.to_id) != from_id):
|
||||||
await yield_(None)
|
await yield_(None)
|
||||||
else:
|
else:
|
||||||
await yield_(custom.Message(self, message, entities, entity))
|
message._finish_init(self, entities, entity)
|
||||||
|
await yield_(message)
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
|
@ -164,8 +164,7 @@ class ChatAction(EventBuilder):
|
||||||
def _set_client(self, client):
|
def _set_client(self, client):
|
||||||
super()._set_client(client)
|
super()._set_client(client)
|
||||||
if self.action_message:
|
if self.action_message:
|
||||||
self.action_message = custom.Message(
|
self.action_message._finish_init(client, self._entities, None)
|
||||||
client, self.action_message, self._entities, None)
|
|
||||||
|
|
||||||
async def respond(self, *args, **kwargs):
|
async def respond(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -204,8 +204,7 @@ class NewMessage(EventBuilder):
|
||||||
|
|
||||||
def _set_client(self, client):
|
def _set_client(self, client):
|
||||||
super()._set_client(client)
|
super()._set_client(client)
|
||||||
self.message = custom.Message(
|
self.message._finish_init(client, self._entities, None)
|
||||||
client, self.message, self._entities, None)
|
|
||||||
self.__dict__['_init'] = True # No new attributes can be set
|
self.__dict__['_init'] = True # No new attributes can be set
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user