mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Update API
This commit is contained in:
@@ -382,13 +382,14 @@ final class HistoryViewStateValidationContexts {
|
||||
}
|
||||
}
|
||||
|
||||
private func hashForScheduledMessages(_ messages: [Message]) -> Int32 {
|
||||
private func hashForScheduledMessages(_ messages: [Message]) -> Int64 {
|
||||
var acc: UInt64 = 0
|
||||
|
||||
let sorted = messages.sorted(by: { $0.timestamp > $1.timestamp })
|
||||
|
||||
for message in sorted {
|
||||
acc = (acc &* 20261) &+ UInt64(message.id.id)
|
||||
combineInt64Hash(&acc, with: UInt64(message.id.id))
|
||||
|
||||
var editTimestamp: Int32 = 0
|
||||
inner: for attribute in message.attributes {
|
||||
if let attribute = attribute as? EditedMessageAttribute {
|
||||
@@ -396,32 +397,40 @@ private func hashForScheduledMessages(_ messages: [Message]) -> Int32 {
|
||||
break inner
|
||||
}
|
||||
}
|
||||
acc = (acc &* 20261) &+ UInt64(editTimestamp)
|
||||
acc = (acc &* 20261) &+ UInt64(message.timestamp)
|
||||
combineInt64Hash(&acc, with: UInt64(editTimestamp))
|
||||
combineInt64Hash(&acc, with: UInt64(message.timestamp))
|
||||
}
|
||||
return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF)))
|
||||
return finalizeInt64Hash(acc)
|
||||
}
|
||||
|
||||
public func combineInt32Hash(_ acc: inout UInt64, with value: UInt64) {
|
||||
acc = (acc &* 20261) &+ value
|
||||
public func combineInt64Hash(_ acc: inout UInt64, with value: UInt64) {
|
||||
acc ^= (acc >> 21)
|
||||
acc ^= (acc << 35)
|
||||
acc ^= (acc >> 4)
|
||||
acc = acc &+ value
|
||||
}
|
||||
|
||||
public func combineInt32Hash(_ acc: inout UInt64, with peerId: PeerId) {
|
||||
public func combineInt64Hash(_ acc: inout UInt64, with peerId: PeerId) {
|
||||
let value = UInt64(bitPattern: peerId.id._internalGetInt64Value())
|
||||
combineInt32Hash(&acc, with: value)
|
||||
combineInt64Hash(&acc, with: value)
|
||||
}
|
||||
|
||||
private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int32 {
|
||||
public func finalizeInt64Hash(_ acc: UInt64) -> Int64 {
|
||||
return Int64(bitPattern: acc)
|
||||
}
|
||||
|
||||
private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int64 {
|
||||
var acc: UInt64 = 0
|
||||
|
||||
let sorted = messages.sorted(by: { $0.index > $1.index })
|
||||
|
||||
for message in sorted {
|
||||
if withChannelIds {
|
||||
combineInt32Hash(&acc, with: message.id.peerId)
|
||||
combineInt64Hash(&acc, with: message.id.peerId)
|
||||
}
|
||||
|
||||
acc = (acc &* 20261) &+ UInt64(message.id.id)
|
||||
|
||||
combineInt64Hash(&acc, with: UInt64(message.id.id))
|
||||
|
||||
var timestamp = message.timestamp
|
||||
inner: for attribute in message.attributes {
|
||||
if let attribute = attribute as? EditedMessageAttribute {
|
||||
@@ -430,22 +439,22 @@ private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int
|
||||
}
|
||||
}
|
||||
if message.tags.contains(.pinned) {
|
||||
acc = (acc &* 20261) &+ UInt64(1)
|
||||
combineInt64Hash(&acc, with: UInt64(1))
|
||||
}
|
||||
acc = (acc &* 20261) &+ UInt64(timestamp)
|
||||
combineInt64Hash(&acc, with: UInt64(timestamp))
|
||||
}
|
||||
return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF)))
|
||||
return finalizeInt64Hash(acc)
|
||||
}
|
||||
|
||||
private func hashForMessages(_ messages: [StoreMessage], withChannelIds: Bool) -> Int32 {
|
||||
private func hashForMessages(_ messages: [StoreMessage], withChannelIds: Bool) -> Int64 {
|
||||
var acc: UInt64 = 0
|
||||
|
||||
for message in messages {
|
||||
if case let .Id(id) = message.id {
|
||||
if withChannelIds {
|
||||
combineInt32Hash(&acc, with: id.peerId)
|
||||
combineInt64Hash(&acc, with: id.peerId)
|
||||
}
|
||||
acc = (acc &* 20261) &+ UInt64(id.id)
|
||||
combineInt64Hash(&acc, with: UInt64(id.id))
|
||||
var timestamp = message.timestamp
|
||||
inner: for attribute in message.attributes {
|
||||
if let attribute = attribute as? EditedMessageAttribute {
|
||||
@@ -453,10 +462,10 @@ private func hashForMessages(_ messages: [StoreMessage], withChannelIds: Bool) -
|
||||
break inner
|
||||
}
|
||||
}
|
||||
acc = (acc &* 20261) &+ UInt64(timestamp)
|
||||
combineInt64Hash(&acc, with: UInt64(timestamp))
|
||||
}
|
||||
}
|
||||
return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF)))
|
||||
return finalizeInt64Hash(acc)
|
||||
}
|
||||
|
||||
private enum ValidatedMessages {
|
||||
|
||||
Reference in New Issue
Block a user