{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"TimeOverlord","type":"basic","slug":"timeoverlord","excerpt":"","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","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"57e0fb0b463a9120006d6e10","githubsync":"","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"MTProto module","slug":"mtproto-module","order":3,"from_sync":false,"reference":false,"_id":"57e0f141ff540c22007b45fa","version":"5703d527bb69fc1700553ce3","createdAt":"2016-09-20T08:20:17.405Z","__v":0,"project":"5703d527bb69fc1700553ce0"},"createdAt":"2016-09-20T09:02:03.696Z","parentDoc":null,"user":"5631f962c3b04b0d00ba9bf1","version":{"version":"0.0.6","version_clean":"0.0.6","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["5703d527bb69fc1700553ce4","5703d8b7aceacc17003ef303","5703e60b6116142000db25f6","57e0db616a1c2e0e0081fe64","57e0f141ff540c22007b45fa","57e0f14b8929550e00f1d9bc"],"_id":"5703d527bb69fc1700553ce3","createdAt":"2016-04-05T15:09:27.620Z","hasDoc":true,"releaseDate":"2016-04-05T15:09:27.620Z","__v":6,"hasReference":true,"project":"5703d527bb69fc1700553ce0"},"__v":0,"project":"5703d527bb69fc1700553ce0"}
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