{"_id":"57e0fb0b463a9120006d6e10","githubsync":"","category":{"_id":"57e0f141ff540c22007b45fa","version":"5703d527bb69fc1700553ce3","__v":0,"project":"5703d527bb69fc1700553ce0","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-09-20T08:20:17.405Z","from_sync":false,"order":3,"slug":"mtproto-module","title":"MTProto module"},"parentDoc":null,"user":"5631f962c3b04b0d00ba9bf1","version":{"_id":"5703d527bb69fc1700553ce3","hasDoc":true,"__v":6,"hasReference":true,"project":"5703d527bb69fc1700553ce0","createdAt":"2016-04-05T15:09:27.620Z","releaseDate":"2016-04-05T15:09:27.620Z","categories":["5703d527bb69fc1700553ce4","5703d8b7aceacc17003ef303","5703e60b6116142000db25f6","57e0db616a1c2e0e0081fe64","57e0f141ff540c22007b45fa","57e0f14b8929550e00f1d9bc"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.6","version":"0.0.6"},"__v":0,"project":"5703d527bb69fc1700553ce0","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-20T09:02:03.696Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"A message id is generated from the timestamp, but Telegram's server may have a slightly different time than ours. TimeOverlord is here to fix that, and will keep the time difference between each of data center and us.\n\n### Weak message id\nA weak message id is a message id generated from the timestamp, but following the mtproto specifications, a message id is unique, it means that two messages (say A and B) being send at the same time (approximately or in the same container) will have two different message id.\nHow does it work?\n- Generate a message id for the first message (say A)\n- Generate a **weak ** message id for the second message (B) \n- A and B will have the same message id because being sent at the same time\n- Increment B by 4 because it comes after A (message id must be modulo 4)\n\nIf we have 3 messages, we'll have:\nmessageId(C) = messageId(B) + 4\nmessageId(B) = messageId(A) + 4\n\nSo when generating a message id, you follow the following algorithm:\n- Generate a **weak message id**\n- Check the latest generated message id\n- Return the max between the weak message id and the latest generated message id + 4","excerpt":"","slug":"timeoverlord","type":"basic","title":"TimeOverlord"}
A message id is generated from the timestamp, but Telegram's server may have a slightly different time than ours. TimeOverlord is here to fix that, and will keep the time difference between each of data center and us. ### Weak message id A weak message id is a message id generated from the timestamp, but following the mtproto specifications, a message id is unique, it means that two messages (say A and B) being send at the same time (approximately or in the same container) will have two different message id. How does it work? - Generate a message id for the first message (say A) - Generate a **weak ** message id for the second message (B) - A and B will have the same message id because being sent at the same time - Increment B by 4 because it comes after A (message id must be modulo 4) If we have 3 messages, we'll have: messageId(C) = messageId(B) + 4 messageId(B) = messageId(A) + 4 So when generating a message id, you follow the following algorithm: - Generate a **weak message id** - Check the latest generated message id - Return the max between the weak message id and the latest generated message id + 4