From e3f307925ed5337cd9953c1141a3a239471601c7 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 25 Jul 2021 12:36:46 +0200 Subject: [PATCH] Update API --- submodules/TelegramApi/Sources/Api0.swift | 18 +-- submodules/TelegramApi/Sources/Api1.swift | 70 ++++----- submodules/TelegramApi/Sources/Api4.swift | 146 +++++++++--------- .../Sources/State/FetchChatList.swift | 2 +- .../State/HistoryViewStateValidation.swift | 51 +++--- .../TelegramCore/Sources/State/Holes.swift | 2 +- .../Sources/State/ManagedRecentStickers.swift | 8 +- ...onizeInstalledStickerPacksOperations.swift | 6 +- .../Sources/State/StickerManagement.swift | 2 +- .../SyncCore_CachedStickerQueryResult.swift | 8 +- .../SyncCore_CachedThemesConfiguration.swift | 8 +- ...ncCore_CachedWallpapersConfiguration.swift | 8 +- .../Contacts/ContactManagement.swift | 12 +- .../TelegramEngine/Peers/ChannelMembers.swift | 2 +- .../Peers/TelegramEnginePeers.swift | 2 +- submodules/TelegramCore/Sources/Themes.swift | 6 +- .../TelegramCore/Sources/Wallpapers.swift | 6 +- .../Sources/PresentationThemeSettings.swift | 10 +- .../ChannelMemberCategoryListContext.swift | 6 +- 19 files changed, 192 insertions(+), 181 deletions(-) diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 5ef4fd3453..13859f9939 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -314,7 +314,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[1679398724] = { return Api.SecureFile.parse_secureFileEmpty($0) } dict[-534283678] = { return Api.SecureFile.parse_secureFile($0) } dict[-199313886] = { return Api.account.Themes.parse_themesNotModified($0) } - dict[2137482273] = { return Api.account.Themes.parse_themes($0) } + dict[-1707242387] = { return Api.account.Themes.parse_themes($0) } dict[236446268] = { return Api.PhotoSize.parse_photoSizeEmpty($0) } dict[1976012384] = { return Api.PhotoSize.parse_photoSize($0) } dict[35527382] = { return Api.PhotoSize.parse_photoCachedSize($0) } @@ -322,13 +322,13 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-96535659] = { return Api.PhotoSize.parse_photoSizeProgressive($0) } dict[-668906175] = { return Api.PhotoSize.parse_photoPathSize($0) } dict[-244016606] = { return Api.messages.Stickers.parse_stickersNotModified($0) } - dict[-463889475] = { return Api.messages.Stickers.parse_stickers($0) } + dict[816245886] = { return Api.messages.Stickers.parse_stickers($0) } dict[-1096616924] = { return Api.GlobalPrivacySettings.parse_globalPrivacySettings($0) } dict[1008755359] = { return Api.InlineBotSwitchPM.parse_inlineBotSwitchPM($0) } dict[223655517] = { return Api.messages.FoundStickerSets.parse_foundStickerSetsNotModified($0) } - dict[1359533640] = { return Api.messages.FoundStickerSets.parse_foundStickerSets($0) } + dict[-1963942446] = { return Api.messages.FoundStickerSets.parse_foundStickerSets($0) } dict[471437699] = { return Api.account.WallPapers.parse_wallPapersNotModified($0) } - dict[1881892265] = { return Api.account.WallPapers.parse_wallPapers($0) } + dict[-842824308] = { return Api.account.WallPapers.parse_wallPapers($0) } dict[1012306921] = { return Api.InputTheme.parse_inputTheme($0) } dict[-175567375] = { return Api.InputTheme.parse_inputThemeSlug($0) } dict[-2032041631] = { return Api.Poll.parse_poll($0) } @@ -574,7 +574,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[190633460] = { return Api.ChatInviteImporter.parse_chatInviteImporter($0) } dict[-2066640507] = { return Api.messages.AffectedMessages.parse_affectedMessages($0) } dict[-402498398] = { return Api.messages.SavedGifs.parse_savedGifsNotModified($0) } - dict[772213157] = { return Api.messages.SavedGifs.parse_savedGifs($0) } + dict[-2069878259] = { return Api.messages.SavedGifs.parse_savedGifs($0) } dict[-914167110] = { return Api.CdnPublicKey.parse_cdnPublicKey($0) } dict[-2083123262] = { return Api.MessageReplies.parse_messageReplies($0) } dict[53231223] = { return Api.InputGame.parse_inputGameID($0) } @@ -673,7 +673,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[721967202] = { return Api.Message.parse_messageService($0) } dict[1398765469] = { return Api.StatsGroupTopInviter.parse_statsGroupTopInviter($0) } dict[186120336] = { return Api.messages.RecentStickers.parse_recentStickersNotModified($0) } - dict[586395571] = { return Api.messages.RecentStickers.parse_recentStickers($0) } + dict[-1999405994] = { return Api.messages.RecentStickers.parse_recentStickers($0) } dict[-539317279] = { return Api.InputFileLocation.parse_inputFileLocation($0) } dict[-182231723] = { return Api.InputFileLocation.parse_inputEncryptedFileLocation($0) } dict[-1160743548] = { return Api.InputFileLocation.parse_inputDocumentFileLocation($0) } @@ -710,7 +710,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[70813275] = { return Api.InputStickeredMedia.parse_inputStickeredMediaDocument($0) } dict[1421174295] = { return Api.WebPageAttribute.parse_webPageAttributeTheme($0) } dict[-958657434] = { return Api.messages.FeaturedStickers.parse_featuredStickersNotModified($0) } - dict[-1230257343] = { return Api.messages.FeaturedStickers.parse_featuredStickers($0) } + dict[-2067782896] = { return Api.messages.FeaturedStickers.parse_featuredStickers($0) } dict[-2048646399] = { return Api.PhoneCallDiscardReason.parse_phoneCallDiscardReasonMissed($0) } dict[-527056480] = { return Api.PhoneCallDiscardReason.parse_phoneCallDiscardReasonDisconnect($0) } dict[1471006352] = { return Api.PhoneCallDiscardReason.parse_phoneCallDiscardReasonHangup($0) } @@ -772,13 +772,13 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[894081801] = { return Api.BotInlineMessage.parse_botInlineMessageMediaInvoice($0) } dict[-1673717362] = { return Api.InputPeerNotifySettings.parse_inputPeerNotifySettings($0) } dict[-1634752813] = { return Api.messages.FavedStickers.parse_favedStickersNotModified($0) } - dict[-209768682] = { return Api.messages.FavedStickers.parse_favedStickers($0) } + dict[750063767] = { return Api.messages.FavedStickers.parse_favedStickers($0) } dict[-1316944408] = { return Api.ExportedChatInvite.parse_chatInviteExported($0) } dict[-1389486888] = { return Api.account.AuthorizationForm.parse_authorizationForm($0) } dict[-1392388579] = { return Api.Authorization.parse_authorization($0) } dict[-1361650766] = { return Api.MaskCoords.parse_maskCoords($0) } dict[-395967805] = { return Api.messages.AllStickers.parse_allStickersNotModified($0) } - dict[-302170017] = { return Api.messages.AllStickers.parse_allStickers($0) } + dict[-843329861] = { return Api.messages.AllStickers.parse_allStickers($0) } dict[-1655957568] = { return Api.PhoneConnection.parse_phoneConnection($0) } dict[1667228533] = { return Api.PhoneConnection.parse_phoneConnectionWebrtc($0) } dict[-206688531] = { return Api.help.UserInfo.parse_userInfoEmpty($0) } diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 4a5d8f065c..e6d8cbf6a1 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -368,7 +368,7 @@ public struct messages { } public enum Stickers: TypeConstructorDescription { case stickersNotModified - case stickers(hash: Int32, stickers: [Api.Document]) + case stickers(hash: Int64, stickers: [Api.Document]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -380,9 +380,9 @@ public struct messages { break case .stickers(let hash, let stickers): if boxed { - buffer.appendInt32(-463889475) + buffer.appendInt32(816245886) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(stickers.count)) for item in stickers { @@ -405,8 +405,8 @@ public struct messages { return Api.messages.Stickers.stickersNotModified } public static func parse_stickers(_ reader: BufferReader) -> Stickers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.Document]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Document.self) @@ -424,7 +424,7 @@ public struct messages { } public enum FoundStickerSets: TypeConstructorDescription { case foundStickerSetsNotModified - case foundStickerSets(hash: Int32, sets: [Api.StickerSetCovered]) + case foundStickerSets(hash: Int64, sets: [Api.StickerSetCovered]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -436,9 +436,9 @@ public struct messages { break case .foundStickerSets(let hash, let sets): if boxed { - buffer.appendInt32(1359533640) + buffer.appendInt32(-1963942446) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(sets.count)) for item in sets { @@ -461,8 +461,8 @@ public struct messages { return Api.messages.FoundStickerSets.foundStickerSetsNotModified } public static func parse_foundStickerSets(_ reader: BufferReader) -> FoundStickerSets? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.StickerSetCovered]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSetCovered.self) @@ -1222,7 +1222,7 @@ public struct messages { } public enum SavedGifs: TypeConstructorDescription { case savedGifsNotModified - case savedGifs(hash: Int32, gifs: [Api.Document]) + case savedGifs(hash: Int64, gifs: [Api.Document]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -1234,9 +1234,9 @@ public struct messages { break case .savedGifs(let hash, let gifs): if boxed { - buffer.appendInt32(772213157) + buffer.appendInt32(-2069878259) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(gifs.count)) for item in gifs { @@ -1259,8 +1259,8 @@ public struct messages { return Api.messages.SavedGifs.savedGifsNotModified } public static func parse_savedGifs(_ reader: BufferReader) -> SavedGifs? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.Document]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Document.self) @@ -1788,7 +1788,7 @@ public struct messages { } public enum RecentStickers: TypeConstructorDescription { case recentStickersNotModified - case recentStickers(hash: Int32, packs: [Api.StickerPack], stickers: [Api.Document], dates: [Int32]) + case recentStickers(hash: Int64, packs: [Api.StickerPack], stickers: [Api.Document], dates: [Int32]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -1800,9 +1800,9 @@ public struct messages { break case .recentStickers(let hash, let packs, let stickers, let dates): if boxed { - buffer.appendInt32(586395571) + buffer.appendInt32(-1999405994) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(packs.count)) for item in packs { @@ -1835,8 +1835,8 @@ public struct messages { return Api.messages.RecentStickers.recentStickersNotModified } public static func parse_recentStickers(_ reader: BufferReader) -> RecentStickers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.StickerPack]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerPack.self) @@ -1864,7 +1864,7 @@ public struct messages { } public enum FeaturedStickers: TypeConstructorDescription { case featuredStickersNotModified(count: Int32) - case featuredStickers(hash: Int32, count: Int32, sets: [Api.StickerSetCovered], unread: [Int64]) + case featuredStickers(hash: Int64, count: Int32, sets: [Api.StickerSetCovered], unread: [Int64]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -1876,9 +1876,9 @@ public struct messages { break case .featuredStickers(let hash, let count, let sets, let unread): if boxed { - buffer.appendInt32(-1230257343) + buffer.appendInt32(-2067782896) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) serializeInt32(count, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(sets.count)) @@ -1915,8 +1915,8 @@ public struct messages { } } public static func parse_featuredStickers(_ reader: BufferReader) -> FeaturedStickers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: Int32? _2 = reader.readInt32() var _3: [Api.StickerSetCovered]? @@ -2092,7 +2092,7 @@ public struct messages { } public enum FavedStickers: TypeConstructorDescription { case favedStickersNotModified - case favedStickers(hash: Int32, packs: [Api.StickerPack], stickers: [Api.Document]) + case favedStickers(hash: Int64, packs: [Api.StickerPack], stickers: [Api.Document]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -2104,9 +2104,9 @@ public struct messages { break case .favedStickers(let hash, let packs, let stickers): if boxed { - buffer.appendInt32(-209768682) + buffer.appendInt32(750063767) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(packs.count)) for item in packs { @@ -2134,8 +2134,8 @@ public struct messages { return Api.messages.FavedStickers.favedStickersNotModified } public static func parse_favedStickers(_ reader: BufferReader) -> FavedStickers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.StickerPack]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerPack.self) @@ -2158,7 +2158,7 @@ public struct messages { } public enum AllStickers: TypeConstructorDescription { case allStickersNotModified - case allStickers(hash: Int32, sets: [Api.StickerSet]) + case allStickers(hash: Int64, sets: [Api.StickerSet]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -2170,9 +2170,9 @@ public struct messages { break case .allStickers(let hash, let sets): if boxed { - buffer.appendInt32(-302170017) + buffer.appendInt32(-843329861) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(sets.count)) for item in sets { @@ -2195,8 +2195,8 @@ public struct messages { return Api.messages.AllStickers.allStickersNotModified } public static func parse_allStickers(_ reader: BufferReader) -> AllStickers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.StickerSet]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.StickerSet.self) diff --git a/submodules/TelegramApi/Sources/Api4.swift b/submodules/TelegramApi/Sources/Api4.swift index 3821b90956..c37cd6abf7 100644 --- a/submodules/TelegramApi/Sources/Api4.swift +++ b/submodules/TelegramApi/Sources/Api4.swift @@ -916,7 +916,7 @@ public struct account { } public enum Themes: TypeConstructorDescription { case themesNotModified - case themes(hash: Int32, themes: [Api.Theme]) + case themes(hash: Int64, themes: [Api.Theme]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -928,9 +928,9 @@ public struct account { break case .themes(let hash, let themes): if boxed { - buffer.appendInt32(2137482273) + buffer.appendInt32(-1707242387) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(themes.count)) for item in themes { @@ -953,8 +953,8 @@ public struct account { return Api.account.Themes.themesNotModified } public static func parse_themes(_ reader: BufferReader) -> Themes? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.Theme]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.Theme.self) @@ -972,7 +972,7 @@ public struct account { } public enum WallPapers: TypeConstructorDescription { case wallPapersNotModified - case wallPapers(hash: Int32, wallpapers: [Api.WallPaper]) + case wallPapers(hash: Int64, wallpapers: [Api.WallPaper]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -984,9 +984,9 @@ public struct account { break case .wallPapers(let hash, let wallpapers): if boxed { - buffer.appendInt32(1881892265) + buffer.appendInt32(-842824308) } - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) buffer.appendInt32(481674261) buffer.appendInt32(Int32(wallpapers.count)) for item in wallpapers { @@ -1009,8 +1009,8 @@ public struct account { return Api.account.WallPapers.wallPapersNotModified } public static func parse_wallPapers(_ reader: BufferReader) -> WallPapers? { - var _1: Int32? - _1 = reader.readInt32() + var _1: Int64? + _1 = reader.readInt64() var _2: [Api.WallPaper]? if let _ = reader.readInt32() { _2 = Api.parseVector(reader, elementSignature: 0, elementType: Api.WallPaper.self) @@ -2023,16 +2023,16 @@ public extension Api { }) } - public static func getDialogs(flags: Int32, folderId: Int32?, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getDialogs(flags: Int32, folderId: Int32?, offsetDate: Int32, offsetId: Int32, offsetPeer: Api.InputPeer, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1594999949) + buffer.appendInt32(-1594569905) serializeInt32(flags, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 1) != 0 {serializeInt32(folderId!, buffer: buffer, boxed: false)} serializeInt32(offsetDate, buffer: buffer, boxed: false) serializeInt32(offsetId, buffer: buffer, boxed: false) offsetPeer.serialize(buffer, true) serializeInt32(limit, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getDialogs", parameters: [("flags", flags), ("folderId", folderId), ("offsetDate", offsetDate), ("offsetId", offsetId), ("offsetPeer", offsetPeer), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Dialogs? in let reader = BufferReader(buffer) var result: Api.messages.Dialogs? @@ -2043,9 +2043,9 @@ public extension Api { }) } - public static func getHistory(peer: Api.InputPeer, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getHistory(peer: Api.InputPeer, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-591691168) + buffer.appendInt32(1143203525) peer.serialize(buffer, true) serializeInt32(offsetId, buffer: buffer, boxed: false) serializeInt32(offsetDate, buffer: buffer, boxed: false) @@ -2053,7 +2053,7 @@ public extension Api { serializeInt32(limit, buffer: buffer, boxed: false) serializeInt32(maxId, buffer: buffer, boxed: false) serializeInt32(minId, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getHistory", parameters: [("peer", peer), ("offsetId", offsetId), ("offsetDate", offsetDate), ("addOffset", addOffset), ("limit", limit), ("maxId", maxId), ("minId", minId), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in let reader = BufferReader(buffer) var result: Api.messages.Messages? @@ -2064,9 +2064,9 @@ public extension Api { }) } - public static func search(flags: Int32, peer: Api.InputPeer, q: String, fromId: Api.InputPeer?, topMsgId: Int32?, filter: Api.MessagesFilter, minDate: Int32, maxDate: Int32, offsetId: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func search(flags: Int32, peer: Api.InputPeer, q: String, fromId: Api.InputPeer?, topMsgId: Int32?, filter: Api.MessagesFilter, minDate: Int32, maxDate: Int32, offsetId: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(204812012) + buffer.appendInt32(-1593989278) serializeInt32(flags, buffer: buffer, boxed: false) peer.serialize(buffer, true) serializeString(q, buffer: buffer, boxed: false) @@ -2080,7 +2080,7 @@ public extension Api { serializeInt32(limit, buffer: buffer, boxed: false) serializeInt32(maxId, buffer: buffer, boxed: false) serializeInt32(minId, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.search", parameters: [("flags", flags), ("peer", peer), ("q", q), ("fromId", fromId), ("topMsgId", topMsgId), ("filter", filter), ("minDate", minDate), ("maxDate", maxDate), ("offsetId", offsetId), ("addOffset", addOffset), ("limit", limit), ("maxId", maxId), ("minId", minId), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in let reader = BufferReader(buffer) var result: Api.messages.Messages? @@ -2601,11 +2601,11 @@ public extension Api { }) } - public static func getStickers(emoticon: String, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getStickers(emoticon: String, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(71126828) + buffer.appendInt32(-710552671) serializeString(emoticon, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getStickers", parameters: [("emoticon", emoticon), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Stickers? in let reader = BufferReader(buffer) var result: Api.messages.Stickers? @@ -2616,10 +2616,10 @@ public extension Api { }) } - public static func getAllStickers(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getAllStickers(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(479598769) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(-1197432408) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getAllStickers", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.AllStickers? in let reader = BufferReader(buffer) var result: Api.messages.AllStickers? @@ -2863,10 +2863,10 @@ public extension Api { }) } - public static func getSavedGifs(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getSavedGifs(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-2084618926) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(1559270965) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getSavedGifs", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.SavedGifs? in let reader = BufferReader(buffer) var result: Api.messages.SavedGifs? @@ -3107,10 +3107,10 @@ public extension Api { }) } - public static func getFeaturedStickers(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getFeaturedStickers(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(766298703) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(1685588756) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getFeaturedStickers", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FeaturedStickers? in let reader = BufferReader(buffer) var result: Api.messages.FeaturedStickers? @@ -3139,11 +3139,11 @@ public extension Api { }) } - public static func getRecentStickers(flags: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getRecentStickers(flags: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1587647177) + buffer.appendInt32(-1649852357) serializeInt32(flags, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getRecentStickers", parameters: [("flags", flags), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.RecentStickers? in let reader = BufferReader(buffer) var result: Api.messages.RecentStickers? @@ -3200,10 +3200,10 @@ public extension Api { }) } - public static func getMaskStickers(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getMaskStickers(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1706608543) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(1678738104) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getMaskStickers", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.AllStickers? in let reader = BufferReader(buffer) var result: Api.messages.AllStickers? @@ -3460,10 +3460,10 @@ public extension Api { }) } - public static func getFavedStickers(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getFavedStickers(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(567151374) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(82946729) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getFavedStickers", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FavedStickers? in let reader = BufferReader(buffer) var result: Api.messages.FavedStickers? @@ -3522,12 +3522,12 @@ public extension Api { }) } - public static func getRecentLocations(peer: Api.InputPeer, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getRecentLocations(peer: Api.InputPeer, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1144759543) + buffer.appendInt32(1881817312) peer.serialize(buffer, true) serializeInt32(limit, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getRecentLocations", parameters: [("peer", peer), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in let reader = BufferReader(buffer) var result: Api.messages.Messages? @@ -3575,12 +3575,12 @@ public extension Api { }) } - public static func searchStickerSets(flags: Int32, q: String, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func searchStickerSets(flags: Int32, q: String, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1028140917) + buffer.appendInt32(896555914) serializeInt32(flags, buffer: buffer, boxed: false) serializeString(q, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.searchStickerSets", parameters: [("flags", flags), ("q", q), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FoundStickerSets? in let reader = BufferReader(buffer) var result: Api.messages.FoundStickerSets? @@ -3889,11 +3889,11 @@ public extension Api { }) } - public static func getScheduledHistory(peer: Api.InputPeer, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getScheduledHistory(peer: Api.InputPeer, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-490575781) + buffer.appendInt32(-183077365) peer.serialize(buffer, true) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getScheduledHistory", parameters: [("peer", peer), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in let reader = BufferReader(buffer) var result: Api.messages.Messages? @@ -4061,12 +4061,12 @@ public extension Api { }) } - public static func getOldFeaturedStickers(offset: Int32, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getOldFeaturedStickers(offset: Int32, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(1608974939) + buffer.appendInt32(2127598753) serializeInt32(offset, buffer: buffer, boxed: false) serializeInt32(limit, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getOldFeaturedStickers", parameters: [("offset", offset), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.FeaturedStickers? in let reader = BufferReader(buffer) var result: Api.messages.FeaturedStickers? @@ -4077,9 +4077,9 @@ public extension Api { }) } - public static func getReplies(peer: Api.InputPeer, msgId: Int32, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getReplies(peer: Api.InputPeer, msgId: Int32, offsetId: Int32, offsetDate: Int32, addOffset: Int32, limit: Int32, maxId: Int32, minId: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(615875002) + buffer.appendInt32(584962828) peer.serialize(buffer, true) serializeInt32(msgId, buffer: buffer, boxed: false) serializeInt32(offsetId, buffer: buffer, boxed: false) @@ -4088,7 +4088,7 @@ public extension Api { serializeInt32(limit, buffer: buffer, boxed: false) serializeInt32(maxId, buffer: buffer, boxed: false) serializeInt32(minId, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "messages.getReplies", parameters: [("peer", peer), ("msgId", msgId), ("offsetId", offsetId), ("offsetDate", offsetDate), ("addOffset", addOffset), ("limit", limit), ("maxId", maxId), ("minId", minId), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.messages.Messages? in let reader = BufferReader(buffer) var result: Api.messages.Messages? @@ -4466,14 +4466,14 @@ public extension Api { }) } - public static func getParticipants(channel: Api.InputChannel, filter: Api.ChannelParticipantsFilter, offset: Int32, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getParticipants(channel: Api.InputChannel, filter: Api.ChannelParticipantsFilter, offset: Int32, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(306054633) + buffer.appendInt32(2010044880) channel.serialize(buffer, true) filter.serialize(buffer, true) serializeInt32(offset, buffer: buffer, boxed: false) serializeInt32(limit, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "channels.getParticipants", parameters: [("channel", channel), ("filter", filter), ("offset", offset), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.channels.ChannelParticipants? in let reader = BufferReader(buffer) var result: Api.channels.ChannelParticipants? @@ -5580,10 +5580,10 @@ public extension Api { } } public struct contacts { - public static func getContactIDs(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Int32]>) { + public static func getContactIDs(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse<[Int32]>) { let buffer = Buffer() - buffer.appendInt32(749357634) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(2061264541) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "contacts.getContactIDs", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> [Int32]? in let reader = BufferReader(buffer) var result: [Int32]? @@ -5608,10 +5608,10 @@ public extension Api { }) } - public static func getContacts(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getContacts(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1071414113) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(1574346258) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "contacts.getContacts", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.contacts.Contacts? in let reader = BufferReader(buffer) var result: Api.contacts.Contacts? @@ -5748,13 +5748,13 @@ public extension Api { }) } - public static func getTopPeers(flags: Int32, offset: Int32, limit: Int32, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getTopPeers(flags: Int32, offset: Int32, limit: Int32, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-728224331) + buffer.appendInt32(-1758168906) serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(offset, buffer: buffer, boxed: false) serializeInt32(limit, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "contacts.getTopPeers", parameters: [("flags", flags), ("offset", offset), ("limit", limit), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.contacts.TopPeers? in let reader = BufferReader(buffer) var result: Api.contacts.TopPeers? @@ -6663,10 +6663,10 @@ public extension Api { }) } - public static func getWallPapers(hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getWallPapers(hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(-1430579357) - serializeInt32(hash, buffer: buffer, boxed: false) + buffer.appendInt32(127302966) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "account.getWallPapers", parameters: [("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.account.WallPapers? in let reader = BufferReader(buffer) var result: Api.account.WallPapers? @@ -7483,11 +7483,11 @@ public extension Api { }) } - public static func getThemes(format: String, hash: Int32) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { + public static func getThemes(format: String, hash: Int64) -> (FunctionDescription, Buffer, DeserializeFunctionResponse) { let buffer = Buffer() - buffer.appendInt32(676939512) + buffer.appendInt32(1913054296) serializeString(format, buffer: buffer, boxed: false) - serializeInt32(hash, buffer: buffer, boxed: false) + serializeInt64(hash, buffer: buffer, boxed: false) return (FunctionDescription(name: "account.getThemes", parameters: [("format", format), ("hash", hash)]), buffer, DeserializeFunctionResponse { (buffer: Buffer) -> Api.account.Themes? in let reader = BufferReader(buffer) var result: Api.account.Themes? diff --git a/submodules/TelegramCore/Sources/State/FetchChatList.swift b/submodules/TelegramCore/Sources/State/FetchChatList.swift index 0f2e5f2619..3bf3163eeb 100644 --- a/submodules/TelegramCore/Sources/State/FetchChatList.swift +++ b/submodules/TelegramCore/Sources/State/FetchChatList.swift @@ -200,7 +200,7 @@ struct FetchedChatList { let peerGroupIds: [PeerId: PeerGroupId] } -func fetchChatList(postbox: Postbox, network: Network, location: FetchChatListLocation, upperBound: MessageIndex, hash: Int32, limit: Int32) -> Signal { +func fetchChatList(postbox: Postbox, network: Network, location: FetchChatListLocation, upperBound: MessageIndex, hash: Int64, limit: Int32) -> Signal { return postbox.stateView() |> mapToSignal { view -> Signal in if let state = view.state as? AuthorizedAccountState { diff --git a/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift b/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift index 1c870410da..ea190a7647 100644 --- a/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift +++ b/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift @@ -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 { diff --git a/submodules/TelegramCore/Sources/State/Holes.swift b/submodules/TelegramCore/Sources/State/Holes.swift index bcfc82068d..24a1d0ced5 100644 --- a/submodules/TelegramCore/Sources/State/Holes.swift +++ b/submodules/TelegramCore/Sources/State/Holes.swift @@ -173,7 +173,7 @@ func fetchMessageHistoryHole(accountPeerId: PeerId, source: FetchMessageHistoryH } |> take(1) |> mapToSignal { _ -> Signal in - return postbox.transaction { transaction -> (Api.InputPeer?, Int32) in + return postbox.transaction { transaction -> (Api.InputPeer?, Int64) in switch peerInput { case let .direct(peerId, _): return (transaction.getPeer(peerId).flatMap(forceApiInputPeer), 0) diff --git a/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift b/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift index 8766950b2e..178d0ace56 100644 --- a/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift +++ b/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift @@ -3,16 +3,16 @@ import Postbox import TelegramApi import SwiftSignalKit -private func hashForIds(_ ids: [Int64]) -> Int32 { +private func hashForIds(_ ids: [Int64]) -> Int64 { var acc: UInt64 = 0 for id in ids { - acc = (acc &* 20261) &+ UInt64(bitPattern: id) + combineInt64Hash(&acc, with: UInt64(bitPattern: id)) } - return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) + return finalizeInt64Hash(acc) } -private func managedRecentMedia(postbox: Postbox, network: Network, collectionId: Int32, reverseHashOrder: Bool, forceFetch: Bool, fetch: @escaping (Int32) -> Signal<[OrderedItemListEntry]?, NoError>) -> Signal { +private func managedRecentMedia(postbox: Postbox, network: Network, collectionId: Int32, reverseHashOrder: Bool, forceFetch: Bool, fetch: @escaping (Int64) -> Signal<[OrderedItemListEntry]?, NoError>) -> Signal { return postbox.transaction { transaction -> Signal in var itemIds = transaction.getOrderedListItemIds(collectionId: collectionId).map { RecentMediaItemId($0).mediaId.id diff --git a/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift b/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift index b5cafa00b1..b482aa427f 100644 --- a/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift @@ -123,14 +123,14 @@ func managedSynchronizeInstalledStickerPacksOperations(postbox: Postbox, network } } -private func hashForStickerPackInfos(_ infos: [StickerPackCollectionInfo]) -> Int32 { +private func hashForStickerPackInfos(_ infos: [StickerPackCollectionInfo]) -> Int64 { var acc: UInt64 = 0 for info in infos { - acc = (acc &* 20261) &+ UInt64(UInt32(bitPattern: info.hash)) + combineInt64Hash(&acc, with: UInt64(UInt32(bitPattern: info.hash))) } - return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) + return finalizeInt64Hash(acc) } private enum SynchronizeInstalledStickerPacksError { diff --git a/submodules/TelegramCore/Sources/State/StickerManagement.swift b/submodules/TelegramCore/Sources/State/StickerManagement.swift index 936014843f..f6109865d7 100644 --- a/submodules/TelegramCore/Sources/State/StickerManagement.swift +++ b/submodules/TelegramCore/Sources/State/StickerManagement.swift @@ -8,7 +8,7 @@ private func hashForIdsReverse(_ ids: [Int64]) -> Int32 { var acc: UInt64 = 0 for id in ids { - acc = (acc &* 20261) &+ UInt64(bitPattern: id) + combineInt64Hash(&acc, with: UInt64(bitPattern: id)) } return Int32(bitPattern: UInt32(clamping: acc & UInt64(0x7FFFFFFF))) } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedStickerQueryResult.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedStickerQueryResult.swift index c9c908af1b..7a0d7769ec 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedStickerQueryResult.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedStickerQueryResult.swift @@ -2,10 +2,10 @@ import Postbox public final class CachedStickerQueryResult: PostboxCoding { public let items: [TelegramMediaFile] - public let hash: Int32 + public let hash: Int64 public let timestamp: Int32 - public init(items: [TelegramMediaFile], hash: Int32, timestamp: Int32) { + public init(items: [TelegramMediaFile], hash: Int64, timestamp: Int32) { self.items = items self.hash = hash self.timestamp = timestamp @@ -13,13 +13,13 @@ public final class CachedStickerQueryResult: PostboxCoding { public init(decoder: PostboxDecoder) { self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! TelegramMediaFile } - self.hash = decoder.decodeInt32ForKey("h", orElse: 0) + self.hash = decoder.decodeInt64ForKey("h6", orElse: 0) self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0) } public func encode(_ encoder: PostboxEncoder) { encoder.encodeObjectArray(self.items, forKey: "it") - encoder.encodeInt32(self.hash, forKey: "h") + encoder.encodeInt64(self.hash, forKey: "h6") encoder.encodeInt32(self.timestamp, forKey: "t") } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedThemesConfiguration.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedThemesConfiguration.swift index f8e473bbfd..2b9f2127d7 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedThemesConfiguration.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedThemesConfiguration.swift @@ -1,17 +1,17 @@ import Postbox public final class CachedThemesConfiguration: PostboxCoding { - public let hash: Int32 + public let hash: Int64 - public init(hash: Int32) { + public init(hash: Int64) { self.hash = hash } public init(decoder: PostboxDecoder) { - self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) + self.hash = decoder.decodeInt64ForKey("hash6", orElse: 0) } public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.hash, forKey: "hash") + encoder.encodeInt64(self.hash, forKey: "hash6") } } diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedWallpapersConfiguration.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedWallpapersConfiguration.swift index fa22f16806..0d6d2ac9da 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedWallpapersConfiguration.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_CachedWallpapersConfiguration.swift @@ -1,17 +1,17 @@ import Postbox public final class CachedWallpapersConfiguration: PostboxCoding { - public let hash: Int32 + public let hash: Int64 - public init(hash: Int32) { + public init(hash: Int64) { self.hash = hash } public init(decoder: PostboxDecoder) { - self.hash = decoder.decodeInt32ForKey("hash", orElse: 0) + self.hash = decoder.decodeInt64ForKey("hash6", orElse: 0) } public func encode(_ encoder: PostboxEncoder) { - encoder.encodeInt32(self.hash, forKey: "hash") + encoder.encodeInt64(self.hash, forKey: "hash6") } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift b/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift index 9beab3d5f0..74ab3af05c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift @@ -10,7 +10,7 @@ private func md5(_ data: Data) -> Data { } } -private func updatedRemoteContactPeers(network: Network, hash: Int32) -> Signal<([Peer], [PeerId: PeerPresence], Int32)?, NoError> { +private func updatedRemoteContactPeers(network: Network, hash: Int64) -> Signal<([Peer], [PeerId: PeerPresence], Int32)?, NoError> { return network.request(Api.functions.contacts.getContacts(hash: hash), automaticFloodWait: false) |> map(Optional.init) |> `catch` { _ -> Signal in @@ -38,19 +38,19 @@ private func updatedRemoteContactPeers(network: Network, hash: Int32) -> Signal< } } -private func hashForCountAndIds(count: Int32, ids: [Int64]) -> Int32 { +private func hashForCountAndIds(count: Int32, ids: [Int64]) -> Int64 { var acc: UInt64 = 0 - acc = (acc &* 20261) &+ UInt64(count) + combineInt64Hash(&acc, with: UInt64(count)) for id in ids { - acc = (acc &* 20261) &+ UInt64(bitPattern: id) + combineInt64Hash(&acc, with: UInt64(bitPattern: id)) } - return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) + return finalizeInt64Hash(acc) } func syncContactsOnce(network: Network, postbox: Postbox, accountPeerId: PeerId) -> Signal { - let initialContactPeerIdsHash = postbox.transaction { transaction -> Int32 in + let initialContactPeerIdsHash = postbox.transaction { transaction -> Int64 in let contactPeerIds = transaction.getContactPeerIds() let totalCount = transaction.getRemoteContactCount() let peerIds = Set(contactPeerIds.filter({ $0.namespace == Namespaces.Peer.CloudUser })) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift index 6e9b01691c..c90226eb26 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift @@ -20,7 +20,7 @@ public enum ChannelMembersCategory { case mentions(threadId: MessageId?, filter: ChannelMembersCategoryFilter) } -func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId, category: ChannelMembersCategory = .recent(.all), offset: Int32 = 0, limit: Int32 = 64, hash: Int32 = 0) -> Signal<[RenderedChannelParticipant]?, NoError> { +func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId: PeerId, peerId: PeerId, category: ChannelMembersCategory = .recent(.all), offset: Int32 = 0, limit: Int32 = 64, hash: Int64 = 0) -> Signal<[RenderedChannelParticipant]?, NoError> { return postbox.transaction { transaction -> Signal<[RenderedChannelParticipant]?, NoError> in if let peer = transaction.getPeer(peerId), let inputChannel = apiInputChannel(peer) { let apiFilter: Api.ChannelParticipantsFilter diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 0d87ea5efb..876dd90374 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -192,7 +192,7 @@ public extension TelegramEngine { return _internal_updateChannelHistoryAvailabilitySettingsInteractively(postbox: self.account.postbox, network: self.account.network, accountStateManager: self.account.stateManager, peerId: peerId, historyAvailableForNewMembers: historyAvailableForNewMembers) } - public func channelMembers(peerId: PeerId, category: ChannelMembersCategory = .recent(.all), offset: Int32 = 0, limit: Int32 = 64, hash: Int32 = 0) -> Signal<[RenderedChannelParticipant]?, NoError> { + public func channelMembers(peerId: PeerId, category: ChannelMembersCategory = .recent(.all), offset: Int32 = 0, limit: Int32 = 64, hash: Int64 = 0) -> Signal<[RenderedChannelParticipant]?, NoError> { return _internal_channelMembers(postbox: self.account.postbox, network: self.account.network, accountPeerId: self.account.peerId, peerId: peerId, category: category, offset: offset, limit: limit, hash: hash) } diff --git a/submodules/TelegramCore/Sources/Themes.swift b/submodules/TelegramCore/Sources/Themes.swift index 07cceeb731..060233a14f 100644 --- a/submodules/TelegramCore/Sources/Themes.swift +++ b/submodules/TelegramCore/Sources/Themes.swift @@ -13,10 +13,10 @@ let telegramThemeFileExtension = "tgios-theme" #endif public func telegramThemes(postbox: Postbox, network: Network, accountManager: AccountManager?, forceUpdate: Bool = false) -> Signal<[TelegramTheme], NoError> { - let fetch: ([TelegramTheme]?, Int32?) -> Signal<[TelegramTheme], NoError> = { current, hash in + let fetch: ([TelegramTheme]?, Int64?) -> Signal<[TelegramTheme], NoError> = { current, hash in network.request(Api.functions.account.getThemes(format: telegramThemeFormat, hash: hash ?? 0)) |> retryRequest - |> mapToSignal { result -> Signal<([TelegramTheme], Int32), NoError> in + |> mapToSignal { result -> Signal<([TelegramTheme], Int64), NoError> in switch result { case let .themes(hash, themes): let result = themes.compactMap { TelegramTheme(apiTheme: $0) } @@ -71,7 +71,7 @@ public func telegramThemes(postbox: Postbox, network: Network, accountManager: A if forceUpdate { return fetch(nil, nil) } else { - return postbox.transaction { transaction -> ([TelegramTheme], Int32?) in + return postbox.transaction { transaction -> ([TelegramTheme], Int64?) in let configuration = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedThemesConfiguration, key: ValueBoxKey(length: 0))) as? CachedThemesConfiguration let items = transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudThemes) return (items.map { $0.contents as! TelegramTheme }, configuration?.hash) diff --git a/submodules/TelegramCore/Sources/Wallpapers.swift b/submodules/TelegramCore/Sources/Wallpapers.swift index eab0ab7c11..7c6136c235 100644 --- a/submodules/TelegramCore/Sources/Wallpapers.swift +++ b/submodules/TelegramCore/Sources/Wallpapers.swift @@ -5,10 +5,10 @@ import TelegramApi public func telegramWallpapers(postbox: Postbox, network: Network, forceUpdate: Bool = false) -> Signal<[TelegramWallpaper], NoError> { - let fetch: ([TelegramWallpaper]?, Int32?) -> Signal<[TelegramWallpaper], NoError> = { current, hash in + let fetch: ([TelegramWallpaper]?, Int64?) -> Signal<[TelegramWallpaper], NoError> = { current, hash in network.request(Api.functions.account.getWallPapers(hash: 0)) |> retryRequest - |> mapToSignal { result -> Signal<([TelegramWallpaper], Int32), NoError> in + |> mapToSignal { result -> Signal<([TelegramWallpaper], Int64), NoError> in switch result { case let .wallPapers(hash, wallpapers): var items: [TelegramWallpaper] = [] @@ -55,7 +55,7 @@ public func telegramWallpapers(postbox: Postbox, network: Network, forceUpdate: if forceUpdate { return fetch(nil, nil) } else { - return postbox.transaction { transaction -> ([TelegramWallpaper], Int32?) in + return postbox.transaction { transaction -> ([TelegramWallpaper], Int64?) in let configuration = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedWallpapersConfiguration, key: ValueBoxKey(length: 0))) as? CachedWallpapersConfiguration let items = transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudWallpapers) if items.count == 0 { diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index 8a41d5e0ea..cf0239ad40 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -205,11 +205,13 @@ public enum PresentationThemeReference: PostboxCoding, Equatable { let id: Int32 func themeId(for id: Int64) -> Int32 { - var acc: UInt64 = 0 + var acc: UInt32 = 0 + let low = UInt32(UInt64(bitPattern: id) & (0xffffffff as UInt64)) + let high = UInt32((UInt64(bitPattern: id) >> 32) & (0xffffffff as UInt64)) + acc = (acc &* 20261) &+ high + acc = (acc &* 20261) &+ low - acc = (acc &* 20261) &+ UInt64(bitPattern: id) - - return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) + return Int32(bitPattern: acc & UInt32(0x7fffffff)) } switch self { diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift index 9bdba14131..55766dd473 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift @@ -205,7 +205,7 @@ private final class ChannelMemberSingleCategoryListContext: ChannelMemberCategor } } - private func loadSignal(offset: Int32, count: Int32, hash: Int32) -> Signal<[RenderedChannelParticipant]?, NoError> { + private func loadSignal(offset: Int32, count: Int32, hash: Int64) -> Signal<[RenderedChannelParticipant]?, NoError> { let requestCategory: ChannelMembersCategory var adminQuery: String? = nil switch self.category { @@ -316,9 +316,9 @@ private final class ChannelMemberSingleCategoryListContext: ChannelMemberCategor for i in 0 ..< min(strongSelf.listStateValue.list.count, Int(initialBatchSize)) { let peerId = strongSelf.listStateValue.list[i].peer.id - combineInt32Hash(&acc, with: peerId) + combineInt64Hash(&acc, with: peerId) } - let hashResult = Int32(bitPattern: UInt32(clamping: acc & UInt64(0x7FFFFFFF))) + let hashResult = finalizeInt64Hash(acc) strongSelf.headUpdateDisposable.set((strongSelf.loadSignal(offset: 0, count: initialBatchSize, hash: hashResult) |> deliverOnMainQueue).start(next: { members in self?.updateHeadMembers(members)