2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 21:07:59 +00:00

Fix BadMsgNotification error_code 32

This commit is contained in:
Dan 2018-02-18 17:31:00 +01:00
parent 3bd3d99e6a
commit d89d238d30
4 changed files with 15 additions and 19 deletions

View File

@ -51,12 +51,12 @@ class Auth:
self.test_mode = test_mode
self.connection = Connection(DataCenter(dc_id, test_mode), proxy)
self.msg_id = MsgId()
def pack(self, data: Object) -> bytes:
@staticmethod
def pack(data: Object) -> bytes:
return (
bytes(8)
+ Long(self.msg_id())
+ Long(MsgId())
+ Int(len(data.write()))
+ data.write()
)

View File

@ -26,14 +26,13 @@ not_content_related = [Ping, HttpWait, MsgsAck, MsgContainer]
class MsgFactory:
def __init__(self, msg_id: MsgId):
self.msg_id = msg_id
def __init__(self):
self.seq_no = SeqNo()
def __call__(self, body: Object) -> Message:
return Message(
body,
self.msg_id(),
MsgId(),
self.seq_no(type(body) not in not_content_related),
len(body)
)

View File

@ -21,17 +21,15 @@ from time import time
class MsgId:
def __init__(self, delta_time: float = 0.0):
self.delta_time = delta_time
self.last_time = 0
self.offset = 0
self.lock = Lock()
last_time = 0
offset = 0
lock = Lock()
def __call__(self) -> int:
with self.lock:
def __new__(cls) -> int:
with cls.lock:
now = time()
self.offset = self.offset + 4 if now == self.last_time else 0
msg_id = int((now + self.delta_time) * 2 ** 32) + self.offset
self.last_time = now
cls.offset = cls.offset + 4 if now == cls.last_time else 0
msg_id = int(now * 2 ** 32) + cls.offset
cls.last_time = now
return msg_id

View File

@ -89,9 +89,8 @@ class Session:
self.auth_key = auth_key
self.auth_key_id = sha1(auth_key).digest()[-8:]
self.msg_id = MsgId()
self.session_id = Long(self.msg_id())
self.msg_factory = MsgFactory(self.msg_id)
self.session_id = Long(MsgId())
self.msg_factory = MsgFactory()
self.current_salt = None