mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-13 20:40:36 +00:00
Create a self-contained MTProtoState
This frees us from using entire Session objects in something that's supposed to just send and receive items from the net.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import struct
|
||||
|
||||
from . import TLObject
|
||||
from .tl_message import TLMessage
|
||||
|
||||
|
||||
class MessageContainer(TLObject):
|
||||
@@ -33,7 +34,8 @@ class MessageContainer(TLObject):
|
||||
inner_msg_id = reader.read_long()
|
||||
inner_sequence = reader.read_int()
|
||||
inner_length = reader.read_int()
|
||||
yield inner_msg_id, inner_sequence, inner_length
|
||||
yield TLMessage(inner_msg_id, inner_sequence,
|
||||
body=reader.read(inner_length))
|
||||
|
||||
def __str__(self):
|
||||
return TLObject.pretty_format(self)
|
||||
|
||||
@@ -20,15 +20,23 @@ class TLMessage(TLObject):
|
||||
sent `TLMessage`, and this result can be represented as a `Future`
|
||||
that will eventually be set with either a result, error or cancelled.
|
||||
"""
|
||||
def __init__(self, session, request, after_id=None):
|
||||
def __init__(self, msg_id, seq_no, body=None, request=None, after_id=0):
|
||||
super().__init__()
|
||||
del self.content_related
|
||||
self.msg_id = session.get_new_msg_id()
|
||||
self.seq_no = session.generate_sequence(request.content_related)
|
||||
self.request = request
|
||||
self.msg_id = msg_id
|
||||
self.seq_no = seq_no
|
||||
self.container_msg_id = None
|
||||
self.future = asyncio.Future()
|
||||
|
||||
# TODO Perhaps it's possible to merge body and request?
|
||||
# We need things like rpc_result and gzip_packed to
|
||||
# be readable by the ``BinaryReader`` for such purpose.
|
||||
|
||||
# Used for incoming, not-decoded messages
|
||||
self.body = body
|
||||
|
||||
# Used for outgoing, not-encoded messages
|
||||
self.request = request
|
||||
|
||||
# After which message ID this one should run. We do this so
|
||||
# InvokeAfterMsgRequest is transparent to the user and we can
|
||||
# easily invoke after while confirming the original request.
|
||||
|
||||
Reference in New Issue
Block a user