diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 0965df57b6..5ef4fd3453 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -68,7 +68,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[693512293] = { return Api.Chat.parse_chatEmpty($0) } dict[1103884886] = { return Api.Chat.parse_chat($0) } dict[1704108455] = { return Api.Chat.parse_chatForbidden($0) } - dict[1106612516] = { return Api.Chat.parse_channel($0) } + dict[-2107528095] = { return Api.Chat.parse_channel($0) } dict[399807445] = { return Api.Chat.parse_channelForbidden($0) } dict[1202287072] = { return Api.StatsURL.parse_statsURL($0) } dict[1516793212] = { return Api.ChatInvite.parse_chatInviteAlready($0) } @@ -860,6 +860,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1676371894] = { return Api.ThemeSettings.parse_themeSettings($0) } dict[-1353671392] = { return Api.PeerNotifySettings.parse_peerNotifySettings($0) } dict[-1995686519] = { return Api.InputBotInlineMessageID.parse_inputBotInlineMessageID($0) } + dict[-1227287081] = { return Api.InputBotInlineMessageID.parse_inputBotInlineMessageID64($0) } dict[-1282352120] = { return Api.PageRelatedArticle.parse_pageRelatedArticle($0) } dict[313694676] = { return Api.StickerPack.parse_stickerPack($0) } dict[1326562017] = { return Api.UserProfilePhoto.parse_userProfilePhotoEmpty($0) } diff --git a/submodules/TelegramApi/Sources/Api2.swift b/submodules/TelegramApi/Sources/Api2.swift index 7c647a0893..ec005626c5 100644 --- a/submodules/TelegramApi/Sources/Api2.swift +++ b/submodules/TelegramApi/Sources/Api2.swift @@ -1747,7 +1747,7 @@ public extension Api { case chatEmpty(id: Int64) case chat(flags: Int32, id: Int64, title: String, photo: Api.ChatPhoto, participantsCount: Int32, date: Int32, version: Int32, migratedTo: Api.InputChannel?, adminRights: Api.ChatAdminRights?, defaultBannedRights: Api.ChatBannedRights?) case chatForbidden(id: Int64, title: String) - case channel(flags: Int32, id: Int64, accessHash: Int64?, title: String, username: String?, photo: Api.ChatPhoto, date: Int32, version: Int32, restrictionReason: [Api.RestrictionReason]?, adminRights: Api.ChatAdminRights?, bannedRights: Api.ChatBannedRights?, defaultBannedRights: Api.ChatBannedRights?, participantsCount: Int32?) + case channel(flags: Int32, id: Int64, accessHash: Int64?, title: String, username: String?, photo: Api.ChatPhoto, date: Int32, restrictionReason: [Api.RestrictionReason]?, adminRights: Api.ChatAdminRights?, bannedRights: Api.ChatBannedRights?, defaultBannedRights: Api.ChatBannedRights?, participantsCount: Int32?) case channelForbidden(flags: Int32, id: Int64, accessHash: Int64, title: String, untilDate: Int32?) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { @@ -1780,9 +1780,9 @@ public extension Api { serializeInt64(id, buffer: buffer, boxed: false) serializeString(title, buffer: buffer, boxed: false) break - case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let version, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount): + case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount): if boxed { - buffer.appendInt32(1106612516) + buffer.appendInt32(-2107528095) } serializeInt32(flags, buffer: buffer, boxed: false) serializeInt64(id, buffer: buffer, boxed: false) @@ -1791,7 +1791,6 @@ public extension Api { if Int(flags) & Int(1 << 6) != 0 {serializeString(username!, buffer: buffer, boxed: false)} photo.serialize(buffer, true) serializeInt32(date, buffer: buffer, boxed: false) - serializeInt32(version, buffer: buffer, boxed: false) if Int(flags) & Int(1 << 9) != 0 {buffer.appendInt32(481674261) buffer.appendInt32(Int32(restrictionReason!.count)) for item in restrictionReason! { @@ -1823,8 +1822,8 @@ public extension Api { return ("chat", [("flags", flags), ("id", id), ("title", title), ("photo", photo), ("participantsCount", participantsCount), ("date", date), ("version", version), ("migratedTo", migratedTo), ("adminRights", adminRights), ("defaultBannedRights", defaultBannedRights)]) case .chatForbidden(let id, let title): return ("chatForbidden", [("id", id), ("title", title)]) - case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let version, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount): - return ("channel", [("flags", flags), ("id", id), ("accessHash", accessHash), ("title", title), ("username", username), ("photo", photo), ("date", date), ("version", version), ("restrictionReason", restrictionReason), ("adminRights", adminRights), ("bannedRights", bannedRights), ("defaultBannedRights", defaultBannedRights), ("participantsCount", participantsCount)]) + case .channel(let flags, let id, let accessHash, let title, let username, let photo, let date, let restrictionReason, let adminRights, let bannedRights, let defaultBannedRights, let participantsCount): + return ("channel", [("flags", flags), ("id", id), ("accessHash", accessHash), ("title", title), ("username", username), ("photo", photo), ("date", date), ("restrictionReason", restrictionReason), ("adminRights", adminRights), ("bannedRights", bannedRights), ("defaultBannedRights", defaultBannedRights), ("participantsCount", participantsCount)]) case .channelForbidden(let flags, let id, let accessHash, let title, let untilDate): return ("channelForbidden", [("flags", flags), ("id", id), ("accessHash", accessHash), ("title", title), ("untilDate", untilDate)]) } @@ -1918,26 +1917,24 @@ public extension Api { } var _7: Int32? _7 = reader.readInt32() - var _8: Int32? - _8 = reader.readInt32() - var _9: [Api.RestrictionReason]? + var _8: [Api.RestrictionReason]? if Int(_1!) & Int(1 << 9) != 0 {if let _ = reader.readInt32() { - _9 = Api.parseVector(reader, elementSignature: 0, elementType: Api.RestrictionReason.self) + _8 = Api.parseVector(reader, elementSignature: 0, elementType: Api.RestrictionReason.self) } } - var _10: Api.ChatAdminRights? + var _9: Api.ChatAdminRights? if Int(_1!) & Int(1 << 14) != 0 {if let signature = reader.readInt32() { - _10 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights + _9 = Api.parse(reader, signature: signature) as? Api.ChatAdminRights + } } + var _10: Api.ChatBannedRights? + if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() { + _10 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights } } var _11: Api.ChatBannedRights? - if Int(_1!) & Int(1 << 15) != 0 {if let signature = reader.readInt32() { + if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() { _11 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights } } - var _12: Api.ChatBannedRights? - if Int(_1!) & Int(1 << 18) != 0 {if let signature = reader.readInt32() { - _12 = Api.parse(reader, signature: signature) as? Api.ChatBannedRights - } } - var _13: Int32? - if Int(_1!) & Int(1 << 17) != 0 {_13 = reader.readInt32() } + var _12: Int32? + if Int(_1!) & Int(1 << 17) != 0 {_12 = reader.readInt32() } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = (Int(_1!) & Int(1 << 13) == 0) || _3 != nil @@ -1945,14 +1942,13 @@ public extension Api { let _c5 = (Int(_1!) & Int(1 << 6) == 0) || _5 != nil let _c6 = _6 != nil let _c7 = _7 != nil - let _c8 = _8 != nil - let _c9 = (Int(_1!) & Int(1 << 9) == 0) || _9 != nil - let _c10 = (Int(_1!) & Int(1 << 14) == 0) || _10 != nil - let _c11 = (Int(_1!) & Int(1 << 15) == 0) || _11 != nil - let _c12 = (Int(_1!) & Int(1 << 18) == 0) || _12 != nil - let _c13 = (Int(_1!) & Int(1 << 17) == 0) || _13 != nil - if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 && _c13 { - return Api.Chat.channel(flags: _1!, id: _2!, accessHash: _3, title: _4!, username: _5, photo: _6!, date: _7!, version: _8!, restrictionReason: _9, adminRights: _10, bannedRights: _11, defaultBannedRights: _12, participantsCount: _13) + let _c8 = (Int(_1!) & Int(1 << 9) == 0) || _8 != nil + let _c9 = (Int(_1!) & Int(1 << 14) == 0) || _9 != nil + let _c10 = (Int(_1!) & Int(1 << 15) == 0) || _10 != nil + let _c11 = (Int(_1!) & Int(1 << 18) == 0) || _11 != nil + let _c12 = (Int(_1!) & Int(1 << 17) == 0) || _12 != nil + if _c1 && _c2 && _c3 && _c4 && _c5 && _c6 && _c7 && _c8 && _c9 && _c10 && _c11 && _c12 { + return Api.Chat.channel(flags: _1!, id: _2!, accessHash: _3, title: _4!, username: _5, photo: _6!, date: _7!, restrictionReason: _8, adminRights: _9, bannedRights: _10, defaultBannedRights: _11, participantsCount: _12) } else { return nil @@ -22045,6 +22041,7 @@ public extension Api { } public enum InputBotInlineMessageID: TypeConstructorDescription { case inputBotInlineMessageID(dcId: Int32, id: Int64, accessHash: Int64) + case inputBotInlineMessageID64(dcId: Int32, ownerId: Int64, id: Int32, accessHash: Int64) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -22056,6 +22053,15 @@ public extension Api { serializeInt64(id, buffer: buffer, boxed: false) serializeInt64(accessHash, buffer: buffer, boxed: false) break + case .inputBotInlineMessageID64(let dcId, let ownerId, let id, let accessHash): + if boxed { + buffer.appendInt32(-1227287081) + } + serializeInt32(dcId, buffer: buffer, boxed: false) + serializeInt64(ownerId, buffer: buffer, boxed: false) + serializeInt32(id, buffer: buffer, boxed: false) + serializeInt64(accessHash, buffer: buffer, boxed: false) + break } } @@ -22063,6 +22069,8 @@ public extension Api { switch self { case .inputBotInlineMessageID(let dcId, let id, let accessHash): return ("inputBotInlineMessageID", [("dcId", dcId), ("id", id), ("accessHash", accessHash)]) + case .inputBotInlineMessageID64(let dcId, let ownerId, let id, let accessHash): + return ("inputBotInlineMessageID64", [("dcId", dcId), ("ownerId", ownerId), ("id", id), ("accessHash", accessHash)]) } } @@ -22083,6 +22091,26 @@ public extension Api { return nil } } + public static func parse_inputBotInlineMessageID64(_ reader: BufferReader) -> InputBotInlineMessageID? { + var _1: Int32? + _1 = reader.readInt32() + var _2: Int64? + _2 = reader.readInt64() + var _3: Int32? + _3 = reader.readInt32() + var _4: Int64? + _4 = reader.readInt64() + let _c1 = _1 != nil + let _c2 = _2 != nil + let _c3 = _3 != nil + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.InputBotInlineMessageID.inputBotInlineMessageID64(dcId: _1!, ownerId: _2!, id: _3!, accessHash: _4!) + } + else { + return nil + } + } } public enum PageRelatedArticle: TypeConstructorDescription { diff --git a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift index 4670065bb9..bca3f90d24 100644 --- a/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift +++ b/submodules/TelegramCallsUI/Sources/CallKitIntegration.swift @@ -169,7 +169,7 @@ class CallKitProviderDelegate: NSObject, CXProviderDelegate { func startCall(context: AccountContext, peerId: PeerId, isVideo: Bool, displayTitle: String) { let uuid = UUID() self.currentStartCallAccount = (uuid, context) - let handle = CXHandle(type: .generic, value: "\(peerId.id. _internalGetInt64Value())") + let handle = CXHandle(type: .generic, value: "\(peerId.id._internalGetInt64Value())") let startCallAction = CXStartCallAction(call: uuid, handle: handle) startCallAction.contactIdentifier = displayTitle diff --git a/submodules/TelegramCore/Sources/Account/AccountIntermediateState.swift b/submodules/TelegramCore/Sources/Account/AccountIntermediateState.swift index 8d9dabfbf5..194cf5a28c 100644 --- a/submodules/TelegramCore/Sources/Account/AccountIntermediateState.swift +++ b/submodules/TelegramCore/Sources/Account/AccountIntermediateState.swift @@ -354,7 +354,7 @@ struct AccountMutableState { for chat in chats { switch chat { - case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount): + case let .channel(_, _, _, _, _, _, _, _, _, _, _, participantsCount): if let participantsCount = participantsCount { self.addOperation(.UpdateCachedPeerData(chat.peerId, { current in var previous: CachedChannelData diff --git a/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift b/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift index 718eadadbe..d4db336c18 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/ApiGroupOrChannel.swift @@ -57,7 +57,7 @@ func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? { return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), title: "", photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) case let .chatForbidden(id, title): return TelegramGroup(id: PeerId(namespace: Namespaces.Peer.CloudGroup, id: PeerId.Id._internalFromInt64Value(id)), title: title, photo: [], participantCount: 0, role: .member, membership: .Removed, flags: [], defaultBannedRights: nil, migrationReference: nil, creationDate: 0, version: 0) - case let .channel(flags, id, accessHash, title, username, photo, date, version, restrictionReason, adminRights, bannedRights, defaultBannedRights, _): + case let .channel(flags, id, accessHash, title, username, photo, date, restrictionReason, adminRights, bannedRights, defaultBannedRights, _): let isMin = (flags & (1 << 12)) != 0 let participationStatus: TelegramChannelParticipationStatus @@ -128,7 +128,7 @@ func parseTelegramGroupOrChannel(chat: Api.Chat) -> Peer? { } } - return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id)), accessHash: accessHashValue, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: date, version: version, participationStatus: participationStatus, info: info, flags: channelFlags, restrictionInfo: restrictionInfo, adminRights: adminRights.flatMap(TelegramChatAdminRights.init), bannedRights: bannedRights.flatMap(TelegramChatBannedRights.init), defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init)) + return TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt64Value(id)), accessHash: accessHashValue, title: title, username: username, photo: imageRepresentationsForApiChatPhoto(photo), creationDate: date, version: 0, participationStatus: participationStatus, info: info, flags: channelFlags, restrictionInfo: restrictionInfo, adminRights: adminRights.flatMap(TelegramChatAdminRights.init), bannedRights: bannedRights.flatMap(TelegramChatBannedRights.init), defaultBannedRights: defaultBannedRights.flatMap(TelegramChatBannedRights.init)) case let .channelForbidden(flags, id, accessHash, title, untilDate): let info: TelegramChannelInfo if (flags & Int32(1 << 8)) != 0 { @@ -145,7 +145,7 @@ func mergeGroupOrChannel(lhs: Peer?, rhs: Api.Chat) -> Peer? { switch rhs { case .chat, .chatEmpty, .chatForbidden, .channelForbidden: return parseTelegramGroupOrChannel(chat: rhs) - case let .channel(flags, _, accessHash, title, username, photo, _, _, _, _, _, defaultBannedRights, _): + case let .channel(flags, _, accessHash, title, username, photo, _, _, _, _, defaultBannedRights, _): let isMin = (flags & (1 << 12)) != 0 if accessHash != nil && !isMin { return parseTelegramGroupOrChannel(chat: rhs) diff --git a/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift b/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift index 3008933dcd..1c870410da 100644 --- a/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift +++ b/submodules/TelegramCore/Sources/State/HistoryViewStateValidation.swift @@ -383,12 +383,12 @@ final class HistoryViewStateValidationContexts { } private func hashForScheduledMessages(_ messages: [Message]) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 let sorted = messages.sorted(by: { $0.timestamp > $1.timestamp }) for message in sorted { - acc = (acc &* 20261) &+ UInt32(message.id.id) + acc = (acc &* 20261) &+ UInt64(message.id.id) var editTimestamp: Int32 = 0 inner: for attribute in message.attributes { if let attribute = attribute as? EditedMessageAttribute { @@ -396,29 +396,23 @@ private func hashForScheduledMessages(_ messages: [Message]) -> Int32 { break inner } } - acc = (acc &* 20261) &+ UInt32(editTimestamp) - acc = (acc &* 20261) &+ UInt32(message.timestamp) + acc = (acc &* 20261) &+ UInt64(editTimestamp) + acc = (acc &* 20261) &+ UInt64(message.timestamp) } - return Int32(bitPattern: acc & UInt32(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } -public func combineInt32Hash(_ acc: inout UInt32, with value: UInt32) { +public func combineInt32Hash(_ acc: inout UInt64, with value: UInt64) { acc = (acc &* 20261) &+ value } -public func combineInt32Hash(_ acc: inout UInt32, with peerId: PeerId) { +public func combineInt32Hash(_ acc: inout UInt64, with peerId: PeerId) { let value = UInt64(bitPattern: peerId.id._internalGetInt64Value()) - let highBits = value >> 32 - let lowBits = value & 0xffffffff - var acc = acc - if highBits != 0 { - combineInt32Hash(&acc, with: UInt32(highBits)) - } - combineInt32Hash(&acc, with: UInt32(lowBits)) + combineInt32Hash(&acc, with: value) } private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 let sorted = messages.sorted(by: { $0.index > $1.index }) @@ -427,7 +421,7 @@ private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int combineInt32Hash(&acc, with: message.id.peerId) } - acc = (acc &* 20261) &+ UInt32(message.id.id) + acc = (acc &* 20261) &+ UInt64(message.id.id) var timestamp = message.timestamp inner: for attribute in message.attributes { if let attribute = attribute as? EditedMessageAttribute { @@ -436,22 +430,22 @@ private func hashForMessages(_ messages: [Message], withChannelIds: Bool) -> Int } } if message.tags.contains(.pinned) { - acc = (acc &* 20261) &+ UInt32(1) + acc = (acc &* 20261) &+ UInt64(1) } - acc = (acc &* 20261) &+ UInt32(timestamp) + acc = (acc &* 20261) &+ UInt64(timestamp) } - return Int32(bitPattern: acc & UInt32(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } private func hashForMessages(_ messages: [StoreMessage], withChannelIds: Bool) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 for message in messages { if case let .Id(id) = message.id { if withChannelIds { combineInt32Hash(&acc, with: id.peerId) } - acc = (acc &* 20261) &+ UInt32(id.id) + acc = (acc &* 20261) &+ UInt64(id.id) var timestamp = message.timestamp inner: for attribute in message.attributes { if let attribute = attribute as? EditedMessageAttribute { @@ -459,10 +453,10 @@ private func hashForMessages(_ messages: [StoreMessage], withChannelIds: Bool) - break inner } } - acc = (acc &* 20261) &+ UInt32(timestamp) + acc = (acc &* 20261) &+ UInt64(timestamp) } } - return Int32(bitPattern: acc & UInt32(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } private enum ValidatedMessages { diff --git a/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift b/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift index ab6ba118be..8766950b2e 100644 --- a/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift +++ b/submodules/TelegramCore/Sources/State/ManagedRecentStickers.swift @@ -3,18 +3,13 @@ import Postbox import TelegramApi import SwiftSignalKit - private func hashForIds(_ ids: [Int64]) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 for id in ids { - 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: acc & UInt32(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } private func managedRecentMedia(postbox: Postbox, network: Network, collectionId: Int32, reverseHashOrder: Bool, forceFetch: Bool, fetch: @escaping (Int32) -> Signal<[OrderedItemListEntry]?, NoError>) -> Signal { diff --git a/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift b/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift index dea3b12676..b5cafa00b1 100644 --- a/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift +++ b/submodules/TelegramCore/Sources/State/ManagedSynchronizeInstalledStickerPacksOperations.swift @@ -124,13 +124,13 @@ func managedSynchronizeInstalledStickerPacksOperations(postbox: Postbox, network } private func hashForStickerPackInfos(_ infos: [StickerPackCollectionInfo]) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 for info in infos { - acc = UInt32(bitPattern: Int32(bitPattern: acc &* UInt32(20261)) &+ info.hash) + acc = (acc &* 20261) &+ UInt64(UInt32(bitPattern: info.hash)) } - return Int32(bitPattern: acc & 0x7FFFFFFF) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } private enum SynchronizeInstalledStickerPacksError { diff --git a/submodules/TelegramCore/Sources/State/StickerManagement.swift b/submodules/TelegramCore/Sources/State/StickerManagement.swift index 9a745f00c8..936014843f 100644 --- a/submodules/TelegramCore/Sources/State/StickerManagement.swift +++ b/submodules/TelegramCore/Sources/State/StickerManagement.swift @@ -5,16 +5,12 @@ import SwiftSignalKit private func hashForIdsReverse(_ ids: [Int64]) -> Int32 { - var acc: UInt32 = 0 + var acc: UInt64 = 0 for id in ids { - 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: acc & UInt32(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0x7FFFFFFF))) } func manageStickerPacks(network: Network, postbox: Postbox) -> Signal { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift b/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift index 5d34565865..e0c836a889 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Calls/GroupCalls.swift @@ -2233,7 +2233,7 @@ func _internal_groupCallDisplayAsAvailablePeers(network: Network, postbox: Postb for chat in chats { if let groupOrChannel = parseTelegramGroupOrChannel(chat: chat) { switch chat { - case let .channel(_, _, _, _, _, _, _, _, _, _, _, _, participantsCount): + case let .channel(_, _, _, _, _, _, _, _, _, _, _, participantsCount): if let participantsCount = participantsCount { subscribers[groupOrChannel.id] = participantsCount } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift b/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift index 140f4692c1..9beab3d5f0 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Contacts/ContactManagement.swift @@ -39,15 +39,14 @@ private func updatedRemoteContactPeers(network: Network, hash: Int32) -> Signal< } private func hashForCountAndIds(count: Int32, ids: [Int64]) -> Int32 { - var acc: Int64 = 0 + var acc: UInt64 = 0 - acc = (acc &* 20261) &+ Int64(count) + acc = (acc &* 20261) &+ UInt64(count) for id in ids { - acc = (acc &* 20261) &+ Int64(id) - acc = acc & Int64(0x7FFFFFFF) + acc = (acc &* 20261) &+ UInt64(bitPattern: id) } - return Int32(acc & Int64(0x7FFFFFFF)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } func syncContactsOnce(network: Network, postbox: Postbox, accountPeerId: PeerId) -> Signal { diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index eae6dee5ec..09e0531d04 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -2325,7 +2325,7 @@ private func accountIdFromNotification(_ notification: UNNotification, sharedCon |> take(1) |> map { _, contexts, _ -> AccountRecordId? in for (_, context, _) in contexts { - if Int(context.account.peerId.id. _internalGetInt64Value()) == userId { + if Int(context.account.peerId.id._internalGetInt64Value()) == userId { return context.account.id } } diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index 6f88ddf8f3..8a41d5e0ea 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -205,13 +205,11 @@ public enum PresentationThemeReference: PostboxCoding, Equatable { let id: Int32 func themeId(for id: Int64) -> Int32 { - 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 + var acc: UInt64 = 0 + + acc = (acc &* 20261) &+ UInt64(bitPattern: id) - return Int32(bitPattern: acc & UInt32(0x7fffffff)) + return Int32(bitPattern: UInt32(clamping: acc & UInt64(0xFFFFFFFF))) } switch self { diff --git a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift index 4ba9e621a6..9bdba14131 100644 --- a/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift +++ b/submodules/TemporaryCachedPeerDataManager/Sources/ChannelMemberCategoryListContext.swift @@ -312,14 +312,14 @@ private final class ChannelMemberSingleCategoryListContext: ChannelMemberCategor return } - var hash: UInt32 = 0 + var acc: UInt64 = 0 for i in 0 ..< min(strongSelf.listStateValue.list.count, Int(initialBatchSize)) { let peerId = strongSelf.listStateValue.list[i].peer.id - combineInt32Hash(&hash, with: peerId) + combineInt32Hash(&acc, with: peerId) } - hash = hash % 0x7FFFFFFF - strongSelf.headUpdateDisposable.set((strongSelf.loadSignal(offset: 0, count: initialBatchSize, hash: Int32(bitPattern: hash)) + let hashResult = Int32(bitPattern: UInt32(clamping: acc & UInt64(0x7FFFFFFF))) + strongSelf.headUpdateDisposable.set((strongSelf.loadSignal(offset: 0, count: initialBatchSize, hash: hashResult) |> deliverOnMainQueue).start(next: { members in self?.updateHeadMembers(members) }))