Skip to content

Commit

Permalink
Fix invoking requests ordered
Browse files Browse the repository at this point in the history
Closes #1709.
  • Loading branch information
Lonami committed Feb 27, 2021
1 parent b475a2e commit a955138
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion telethon/network/mtprotostate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@
from ..errors import SecurityError, InvalidBufferError
from ..extensions import BinaryReader
from ..tl.core import TLMessage
from ..tl.tlobject import TLRequest
from ..tl.functions import InvokeAfterMsgRequest
from ..tl.core.gzippacked import GzipPacked


class _OpaqueRequest(TLRequest):
"""
Wraps a serialized request into a type that can be serialized again.
"""
def __init__(self, data: bytes):
self.data = data

def _bytes(self):
return self.data



class MTProtoState:
"""
`telethon.network.mtprotosender.MTProtoSender` needs to hold a state
Expand Down Expand Up @@ -87,8 +100,10 @@ def write_data_as_message(self, buffer, data, content_related,
if after_id is None:
body = GzipPacked.gzip_if_smaller(content_related, data)
else:
# The `RequestState` stores `bytes(request)`, not the request itself.
# `invokeAfterMsg` wants a `TLRequest` though, hence the wrapping.
body = GzipPacked.gzip_if_smaller(content_related,
bytes(InvokeAfterMsgRequest(after_id, data)))
bytes(InvokeAfterMsgRequest(after_id, _OpaqueRequest(data))))

buffer.write(struct.pack('<qii', msg_id, seq_no, len(body)))
buffer.write(body)
Expand Down

0 comments on commit a955138

Please sign in to comment.