From d5832e4f3be8ae8afcabc14b3075fa19990cacf4 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 27 Feb 2018 11:41:45 +0100 Subject: [PATCH] Fix time offset failing if system time was ahead of time While the offset was working, the last message ID was never reset, so it would always pick an higher message ID (safety check), which completely defeated the purpose of negative time offsets. Should close #496. --- telethon/session.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/telethon/session.py b/telethon/session.py index faa1516f..6b374c39 100644 --- a/telethon/session.py +++ b/telethon/session.py @@ -325,10 +325,10 @@ class Session: """Generates a new unique message ID based on the current time (in ms) since epoch""" # Refer to mtproto_plain_sender.py for the original method - now = time.time() + now = time.time() + self.time_offset nanoseconds = int((now - int(now)) * 1e+9) # "message identifiers are divisible by 4" - new_msg_id = ((int(now) + self.time_offset) << 32) | (nanoseconds << 2) + new_msg_id = (int(now) << 32) | (nanoseconds << 2) with self._msg_id_lock: if self._last_msg_id >= new_msg_id: @@ -343,6 +343,7 @@ class Session: now = int(time.time()) correct = correct_msg_id >> 32 self.time_offset = correct - now + self._last_msg_id = 0 # Entity processing