From 0686ec44403e9fb7e71eceadaa23870c63db702b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 19 Oct 2018 16:53:50 +0200 Subject: [PATCH] Implement after_msg_id back --- telethon/extensions/messagepacker.py | 4 ++-- telethon/network/mtprotosender.py | 8 +++----- telethon/network/requeststate.py | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/telethon/extensions/messagepacker.py b/telethon/extensions/messagepacker.py index 23df601b..3944afe6 100644 --- a/telethon/extensions/messagepacker.py +++ b/telethon/extensions/messagepacker.py @@ -71,9 +71,9 @@ class MessagePacker: size += len(state.data) + TLMessage.SIZE_OVERHEAD if size <= MessageContainer.MAXIMUM_SIZE: - # TODO Implement back using after_id state.msg_id = self._state.write_data_as_message( - buffer, state.data, isinstance(state.request, TLRequest) + buffer, state.data, isinstance(state.request, TLRequest), + after_id=state.after.msg_id if state.after else None ) batch.append(state) __log__.debug('Assigned msg_id = %d to %s (%x)', diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 0d2fa3f4..462aa22a 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -161,15 +161,13 @@ class MTProtoSender: else: states = [] futures = [] + state = None for req in request: - state = RequestState(req, self._loop) + state = RequestState(req, self._loop, after=ordered and state) states.append(state) futures.append(state.future) - if ordered: - self._send_queue.append(states) - else: - self._send_queue.extend(states) + self._send_queue.extend(states) return futures @property diff --git a/telethon/network/requeststate.py b/telethon/network/requeststate.py index 018832af..eb598e24 100644 --- a/telethon/network/requeststate.py +++ b/telethon/network/requeststate.py @@ -8,11 +8,12 @@ class RequestState: it belongs to, the request itself, the request as bytes, and the future result that will eventually be resolved. """ - __slots__ = ('container_id', 'msg_id', 'request', 'data', 'future') + __slots__ = ('container_id', 'msg_id', 'request', 'data', 'future', 'after') - def __init__(self, request, loop): + def __init__(self, request, loop, after=None): self.container_id = None self.msg_id = None self.request = request self.data = bytes(request) self.future = asyncio.Future(loop=loop) + self.after = after