Skip to content

Commit

Permalink
Possible fix of xelaj#49
Browse files Browse the repository at this point in the history
  • Loading branch information
hookzof authored Jul 11, 2021
1 parent 04ee89d commit d34eb2c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ import (
"time"
)

var lastMessageId int64

// GenerateMessageId отдает по сути unix timestamp но ужасно специфическим образом
// TODO: нахуя нужно битовое и на -4??
func GenerateMessageId() int64 {
func GenerateMessageId() (r int64) {
const billion = 1000 * 1000 * 1000
unixnano := time.Now().UnixNano()
seconds := unixnano / billion
nanoseconds := unixnano % billion
return (seconds << 32) | (nanoseconds & -4)
r = (seconds << 32) | (nanoseconds & -4)
if r == lastMessageId {
r += 4
}
lastMessageId = r
return r
}

func AuthKeyHash(key []byte) []byte {
Expand Down

0 comments on commit d34eb2c

Please sign in to comment.