diff --git a/SiriIntents/IntentHandler.swift b/SiriIntents/IntentHandler.swift index 9083112cb9..46253f0897 100644 --- a/SiriIntents/IntentHandler.swift +++ b/SiriIntents/IntentHandler.swift @@ -106,7 +106,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo let deviceSpecificEncryptionParameters = BuildConfig.deviceSpecificEncryptionParameters(rootPath, baseAppBundleId: baseAppBundleId) let encryptionParameters = ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: deviceSpecificEncryptionParameters.key)!, salt: ValueBoxEncryptionParameters.Salt(data: deviceSpecificEncryptionParameters.salt)!) - account = currentAccount(allocateIfNotExists: false, networkArguments: NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, appData: .single(buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), supplementary: true, manager: accountManager, rootPath: rootPath, auxiliaryMethods: accountAuxiliaryMethods, encryptionParameters: encryptionParameters) + account = currentAccount(allocateIfNotExists: false, networkArguments: NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: 0, voipVersions: [], appData: .single(buildConfig.bundleData(withAppToken: nil, signatureDict: nil)), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), supplementary: true, manager: accountManager, rootPath: rootPath, auxiliaryMethods: accountAuxiliaryMethods, encryptionParameters: encryptionParameters) |> mapToSignal { account -> Signal in if let account = account { switch account { diff --git a/submodules/SyncCore/Sources/Namespaces.swift b/submodules/SyncCore/Sources/Namespaces.swift index 1af4170023..7b384619c8 100644 --- a/submodules/SyncCore/Sources/Namespaces.swift +++ b/submodules/SyncCore/Sources/Namespaces.swift @@ -43,6 +43,7 @@ public struct Namespaces { public static let CloudMaskPacks: Int32 = 1 public static let EmojiKeywords: Int32 = 2 public static let CloudAnimatedEmoji: Int32 = 3 + public static let CloudDice: Int32 = 4 } public struct OrderedItemList { diff --git a/submodules/SyncCore/Sources/TelegramMediaFile.swift b/submodules/SyncCore/Sources/TelegramMediaFile.swift index 535e7eae78..072ae24ca0 100644 --- a/submodules/SyncCore/Sources/TelegramMediaFile.swift +++ b/submodules/SyncCore/Sources/TelegramMediaFile.swift @@ -12,6 +12,7 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { case id(id: Int64, accessHash: Int64) case name(String) case animatedEmoji + case dice public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("r", orElse: 0) { @@ -21,6 +22,8 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { self = .name(decoder.decodeStringForKey("n", orElse: "")) case 2: self = .animatedEmoji + case 3: + self = .dice default: self = .name("") assertionFailure() @@ -38,6 +41,8 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { encoder.encodeString(name, forKey: "n") case .animatedEmoji: encoder.encodeInt32(2, forKey: "r") + case .dice: + encoder.encodeInt32(3, forKey: "r") } } @@ -61,6 +66,12 @@ public enum StickerPackReference: PostboxCoding, Hashable, Equatable { } else { return false } + case .dice: + if case .dice = rhs { + return true + } else { + return false + } } } } diff --git a/submodules/TelegramApi/Sources/Api0.swift b/submodules/TelegramApi/Sources/Api0.swift index 26baa33fef..afd8f5b371 100644 --- a/submodules/TelegramApi/Sources/Api0.swift +++ b/submodules/TelegramApi/Sources/Api0.swift @@ -513,7 +513,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1502174430] = { return Api.InputMessage.parse_inputMessageID($0) } dict[-1160215659] = { return Api.InputMessage.parse_inputMessageReplyTo($0) } dict[-2037963464] = { return Api.InputMessage.parse_inputMessagePinned($0) } - dict[-1564789301] = { return Api.PhoneCallProtocol.parse_phoneCallProtocol($0) } + dict[-58224696] = { return Api.PhoneCallProtocol.parse_phoneCallProtocol($0) } dict[-1237848657] = { return Api.StatsDateRangeDays.parse_statsDateRangeDays($0) } dict[-1567175714] = { return Api.MessageFwdAuthor.parse_messageFwdAuthor($0) } dict[-1539849235] = { return Api.WallPaper.parse_wallPaper($0) } @@ -579,6 +579,7 @@ fileprivate let parsers: [Int32 : (BufferReader) -> Any?] = { dict[-1645763991] = { return Api.InputStickerSet.parse_inputStickerSetID($0) } dict[-2044933984] = { return Api.InputStickerSet.parse_inputStickerSetShortName($0) } dict[42402760] = { return Api.InputStickerSet.parse_inputStickerSetAnimatedEmoji($0) } + dict[2044861011] = { return Api.InputStickerSet.parse_inputStickerSetDice($0) } dict[-1729618630] = { return Api.BotInfo.parse_botInfo($0) } dict[-1519637954] = { return Api.updates.State.parse_state($0) } dict[372165663] = { return Api.FoundGif.parse_foundGif($0) } diff --git a/submodules/TelegramApi/Sources/Api1.swift b/submodules/TelegramApi/Sources/Api1.swift index 1046f9f6f9..790975a865 100644 --- a/submodules/TelegramApi/Sources/Api1.swift +++ b/submodules/TelegramApi/Sources/Api1.swift @@ -14600,25 +14600,30 @@ public extension Api { } public enum PhoneCallProtocol: TypeConstructorDescription { - case phoneCallProtocol(flags: Int32, minLayer: Int32, maxLayer: Int32) + case phoneCallProtocol(flags: Int32, minLayer: Int32, maxLayer: Int32, libraryVersions: [String]) public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { - case .phoneCallProtocol(let flags, let minLayer, let maxLayer): + case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): if boxed { - buffer.appendInt32(-1564789301) + buffer.appendInt32(-58224696) } serializeInt32(flags, buffer: buffer, boxed: false) serializeInt32(minLayer, buffer: buffer, boxed: false) serializeInt32(maxLayer, buffer: buffer, boxed: false) + buffer.appendInt32(481674261) + buffer.appendInt32(Int32(libraryVersions.count)) + for item in libraryVersions { + serializeString(item, buffer: buffer, boxed: false) + } break } } public func descriptionFields() -> (String, [(String, Any)]) { switch self { - case .phoneCallProtocol(let flags, let minLayer, let maxLayer): - return ("phoneCallProtocol", [("flags", flags), ("minLayer", minLayer), ("maxLayer", maxLayer)]) + case .phoneCallProtocol(let flags, let minLayer, let maxLayer, let libraryVersions): + return ("phoneCallProtocol", [("flags", flags), ("minLayer", minLayer), ("maxLayer", maxLayer), ("libraryVersions", libraryVersions)]) } } @@ -14629,11 +14634,16 @@ public extension Api { _2 = reader.readInt32() var _3: Int32? _3 = reader.readInt32() + var _4: [String]? + if let _ = reader.readInt32() { + _4 = Api.parseVector(reader, elementSignature: -1255641564, elementType: String.self) + } let _c1 = _1 != nil let _c2 = _2 != nil let _c3 = _3 != nil - if _c1 && _c2 && _c3 { - return Api.PhoneCallProtocol.phoneCallProtocol(flags: _1!, minLayer: _2!, maxLayer: _3!) + let _c4 = _4 != nil + if _c1 && _c2 && _c3 && _c4 { + return Api.PhoneCallProtocol.phoneCallProtocol(flags: _1!, minLayer: _2!, maxLayer: _3!, libraryVersions: _4!) } else { return nil @@ -16258,6 +16268,7 @@ public extension Api { case inputStickerSetID(id: Int64, accessHash: Int64) case inputStickerSetShortName(shortName: String) case inputStickerSetAnimatedEmoji + case inputStickerSetDice public func serialize(_ buffer: Buffer, _ boxed: Swift.Bool) { switch self { @@ -16285,6 +16296,12 @@ public extension Api { buffer.appendInt32(42402760) } + break + case .inputStickerSetDice: + if boxed { + buffer.appendInt32(2044861011) + } + break } } @@ -16299,6 +16316,8 @@ public extension Api { return ("inputStickerSetShortName", [("shortName", shortName)]) case .inputStickerSetAnimatedEmoji: return ("inputStickerSetAnimatedEmoji", []) + case .inputStickerSetDice: + return ("inputStickerSetDice", []) } } @@ -16333,6 +16352,9 @@ public extension Api { public static func parse_inputStickerSetAnimatedEmoji(_ reader: BufferReader) -> InputStickerSet? { return Api.InputStickerSet.inputStickerSetAnimatedEmoji } + public static func parse_inputStickerSetDice(_ reader: BufferReader) -> InputStickerSet? { + return Api.InputStickerSet.inputStickerSetDice + } } public enum BotInfo: TypeConstructorDescription { diff --git a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift index 6bfda0df93..2e5310dec2 100644 --- a/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift +++ b/submodules/TelegramCallsUI/Sources/PresentationCallManager.swift @@ -75,6 +75,10 @@ public final class PresentationCallManagerImpl: PresentationCallManager { return OngoingCallContext.maxLayer } + public static var voipVersions: [String] { + return [OngoingCallContext.version] + } + public init(accountManager: AccountManager, getDeviceAccessData: @escaping () -> (presentationData: PresentationData, present: (ViewController, Any?) -> Void, openSettings: () -> Void), isMediaPlaying: @escaping () -> Bool, resumeMediaPlayback: @escaping () -> Void, audioSession: ManagedAudioSession, activeAccounts: Signal<[Account], NoError>) { self.getDeviceAccessData = getDeviceAccessData self.accountManager = accountManager diff --git a/submodules/TelegramCore/Sources/Account.swift b/submodules/TelegramCore/Sources/Account.swift index d28d1ee0a1..990e0a5ff1 100644 --- a/submodules/TelegramCore/Sources/Account.swift +++ b/submodules/TelegramCore/Sources/Account.swift @@ -901,7 +901,7 @@ public class Account { self.supplementary = supplementary self.peerInputActivityManager = PeerInputActivityManager() - self.callSessionManager = CallSessionManager(postbox: postbox, network: network, maxLayer: networkArguments.voipMaxLayer, addUpdates: { [weak self] updates in + self.callSessionManager = CallSessionManager(postbox: postbox, network: network, maxLayer: networkArguments.voipMaxLayer, versions: networkArguments.voipVersions, addUpdates: { [weak self] updates in self?.stateManager?.addUpdates(updates) }) self.stateManager = AccountStateManager(accountPeerId: self.peerId, accountManager: accountManager, postbox: self.postbox, network: self.network, callSessionManager: self.callSessionManager, addIsContactUpdates: { [weak self] updates in diff --git a/submodules/TelegramCore/Sources/CachedStickerPack.swift b/submodules/TelegramCore/Sources/CachedStickerPack.swift index 00f7a95fc4..4582c64171 100644 --- a/submodules/TelegramCore/Sources/CachedStickerPack.swift +++ b/submodules/TelegramCore/Sources/CachedStickerPack.swift @@ -76,6 +76,20 @@ public func cachedStickerPack(postbox: Postbox, network: Network, reference: Sti } else { return (.fetching, true, nil) } + case .dice: + let namespace = Namespaces.ItemCollection.CloudDice + let id: ItemCollectionId.Id = 0 + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { + previousHash = cached.hash + let current: CachedStickerPackResult = .result(info, cached.items, false) + if cached.hash != info.hash { + return (current, true, previousHash) + } else { + return (current, true, previousHash) + } + } else { + return (.fetching, true, nil) + } } } |> mapToSignal { result, loadRemote, previousHash in @@ -148,6 +162,18 @@ func cachedStickerPack(transaction: Transaction, reference: StickerPackReference if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { return (info, cached.items, false) } + case .dice: + let namespace = Namespaces.ItemCollection.CloudDice + let id: ItemCollectionId.Id = 0 + if let currentInfo = transaction.getItemCollectionInfo(collectionId: ItemCollectionId(namespace: namespace, id: id)) as? StickerPackCollectionInfo { + let items = transaction.getItemCollectionItems(collectionId: ItemCollectionId(namespace: namespace, id: id)) + if !items.isEmpty { + return (currentInfo, items, true) + } + } + if let cached = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.cachedStickerPacks, key: CachedStickerPack.cacheKey(ItemCollectionId(namespace: namespace, id: id)))) as? CachedStickerPack, let info = cached.info { + return (info, cached.items, false) + } } return nil } diff --git a/submodules/TelegramCore/Sources/CallSessionManager.swift b/submodules/TelegramCore/Sources/CallSessionManager.swift index a84206744b..301a47a4ee 100644 --- a/submodules/TelegramCore/Sources/CallSessionManager.swift +++ b/submodules/TelegramCore/Sources/CallSessionManager.swift @@ -4,7 +4,6 @@ import MtProtoKit import SwiftSignalKit import TelegramApi - import SyncCore private let minLayer: Int32 = 65 @@ -241,6 +240,7 @@ private final class CallSessionManagerContext { private let postbox: Postbox private let network: Network private let maxLayer: Int32 + private let versions: [String] private let addUpdates: (Api.Updates) -> Void private let ringingSubscribers = Bag<([CallSessionRingingState]) -> Void>() @@ -249,11 +249,12 @@ private final class CallSessionManagerContext { private let disposables = DisposableSet() - init(queue: Queue, postbox: Postbox, network: Network, maxLayer: Int32, addUpdates: @escaping (Api.Updates) -> Void) { + init(queue: Queue, postbox: Postbox, network: Network, maxLayer: Int32, versions: [String], addUpdates: @escaping (Api.Updates) -> Void) { self.queue = queue self.postbox = postbox self.network = network self.maxLayer = maxLayer + self.versions = versions self.addUpdates = addUpdates } @@ -469,7 +470,7 @@ private final class CallSessionManagerContext { if let context = self.contexts[internalId] { switch context.state { case let .ringing(id, accessHash, gAHash, b): - context.state = .accepting(id: id, accessHash: accessHash, gAHash: gAHash, b: b, disposable: (acceptCallSession(postbox: self.postbox, network: self.network, stableId: id, accessHash: accessHash, b: b, maxLayer: self.maxLayer) |> deliverOn(self.queue)).start(next: { [weak self] result in + context.state = .accepting(id: id, accessHash: accessHash, gAHash: gAHash, b: b, disposable: (acceptCallSession(postbox: self.postbox, network: self.network, stableId: id, accessHash: accessHash, b: b, maxLayer: self.maxLayer, versions: self.versions) |> deliverOn(self.queue)).start(next: { [weak self] result in if let strongSelf = self, let context = strongSelf.contexts[internalId] { if case .accepting = context.state { switch result { @@ -534,7 +535,7 @@ private final class CallSessionManagerContext { let keyVisualHash = MTSha256(key + gA)! - context.state = .confirming(id: id, accessHash: accessHash, key: key, keyId: keyId, keyVisualHash: keyVisualHash, disposable: (confirmCallSession(network: self.network, stableId: id, accessHash: accessHash, gA: gA, keyFingerprint: keyId, maxLayer: self.maxLayer) |> deliverOnMainQueue).start(next: { [weak self] updatedCall in + context.state = .confirming(id: id, accessHash: accessHash, key: key, keyId: keyId, keyVisualHash: keyVisualHash, disposable: (confirmCallSession(network: self.network, stableId: id, accessHash: accessHash, gA: gA, keyFingerprint: keyId, maxLayer: self.maxLayer, versions: self.versions) |> deliverOnMainQueue).start(next: { [weak self] updatedCall in if let strongSelf = self, let context = strongSelf.contexts[internalId], case .confirming = context.state { if let updatedCall = updatedCall { strongSelf.updateSession(updatedCall, completion: { _ in }) @@ -616,7 +617,7 @@ private final class CallSessionManagerContext { if let (key, calculatedKeyId, keyVisualHash) = self.makeSessionEncryptionKey(config: config, gAHash: gAHash, b: b, gA: gAOrB.makeData()) { if keyFingerprint == calculatedKeyId { switch callProtocol { - case let .phoneCallProtocol(_, _, maxLayer): + case let .phoneCallProtocol(_, _, maxLayer, _): context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: calculatedKeyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connections.first!, alternative: Array(connections[1...])), maxLayer: maxLayer, allowsP2P: allowsP2P) self.contextUpdated(internalId: internalId) } @@ -628,7 +629,7 @@ private final class CallSessionManagerContext { } case let .confirming(id, accessHash, key, keyId, keyVisualHash, _): switch callProtocol { - case let .phoneCallProtocol(_, _, maxLayer): + case let .phoneCallProtocol(_, _, maxLayer, _): context.state = .active(id: id, accessHash: accessHash, beginTimestamp: startDate, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: parseConnectionSet(primary: connections.first!, alternative: Array(connections[1...])), maxLayer: maxLayer, allowsP2P: allowsP2P) self.contextUpdated(internalId: internalId) } @@ -709,7 +710,7 @@ private final class CallSessionManagerContext { let randomStatus = SecRandomCopyBytes(nil, 256, aBytes.assumingMemoryBound(to: UInt8.self)) let a = Data(bytesNoCopy: aBytes, count: 256, deallocator: .free) if randomStatus == 0 { - self.contexts[internalId] = CallSessionContext(peerId: peerId, isOutgoing: true, state: .requesting(a: a, disposable: (requestCallSession(postbox: self.postbox, network: self.network, peerId: peerId, a: a, maxLayer: self.maxLayer) |> deliverOn(queue)).start(next: { [weak self] result in + self.contexts[internalId] = CallSessionContext(peerId: peerId, isOutgoing: true, state: .requesting(a: a, disposable: (requestCallSession(postbox: self.postbox, network: self.network, peerId: peerId, a: a, maxLayer: self.maxLayer, versions: self.versions) |> deliverOn(queue)).start(next: { [weak self] result in if let strongSelf = self, let context = strongSelf.contexts[internalId] { if case .requesting = context.state { switch result { @@ -743,9 +744,9 @@ public final class CallSessionManager { private let queue = Queue() private var contextRef: Unmanaged? - init(postbox: Postbox, network: Network, maxLayer: Int32, addUpdates: @escaping (Api.Updates) -> Void) { + init(postbox: Postbox, network: Network, maxLayer: Int32, versions: [String], addUpdates: @escaping (Api.Updates) -> Void) { self.queue.async { - let context = CallSessionManagerContext(queue: self.queue, postbox: postbox, network: network, maxLayer: maxLayer, addUpdates: addUpdates) + let context = CallSessionManagerContext(queue: self.queue, postbox: postbox, network: network, maxLayer: maxLayer, versions: versions, addUpdates: addUpdates) self.contextRef = Unmanaged.passRetained(context) } } @@ -846,7 +847,7 @@ private enum AcceptCallResult { case success(AcceptedCall) } -private func acceptCallSession(postbox: Postbox, network: Network, stableId: CallSessionStableId, accessHash: Int64, b: Data, maxLayer: Int32) -> Signal { +private func acceptCallSession(postbox: Postbox, network: Network, stableId: CallSessionStableId, accessHash: Int64, b: Data, maxLayer: Int32, versions: [String]) -> Signal { return validatedEncryptionConfig(postbox: postbox, network: network) |> mapToSignal { config -> Signal in var gValue: Int32 = config.g.byteSwapped @@ -860,8 +861,8 @@ private func acceptCallSession(postbox: Postbox, network: Network, stableId: Cal if !MTCheckIsSafeGAOrB(network.encryptionProvider, gb, p) { return .single(.failed) } - - return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(id: stableId, accessHash: accessHash), gB: Buffer(data: gb), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer))) + + return network.request(Api.functions.phone.acceptCall(peer: .inputPhoneCall(id: stableId, accessHash: accessHash), gB: Buffer(data: gb), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) @@ -887,7 +888,7 @@ private func acceptCallSession(postbox: Postbox, network: Network, stableId: Cal case let .phoneCall(flags, id, _, _, _, _, gAOrB, _, callProtocol, connections, startDate): if id == stableId { switch callProtocol{ - case let .phoneCallProtocol(_, _, maxLayer): + case let .phoneCallProtocol(_, _, maxLayer, _): return .success(.call(config: config, gA: gAOrB.makeData(), timestamp: startDate, connections: parseConnectionSet(primary: connections.first!, alternative: Array(connections[1...])), maxLayer: maxLayer, allowsP2P: (flags & (1 << 5)) != 0)) } } else { @@ -908,7 +909,7 @@ private enum RequestCallSessionResult { case failed(CallSessionError) } -private func requestCallSession(postbox: Postbox, network: Network, peerId: PeerId, a: Data, maxLayer: Int32) -> Signal { +private func requestCallSession(postbox: Postbox, network: Network, peerId: PeerId, a: Data, maxLayer: Int32, versions: [String]) -> Signal { return validatedEncryptionConfig(postbox: postbox, network: network) |> mapToSignal { config -> Signal in return postbox.transaction { transaction -> Signal in @@ -924,7 +925,7 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer let gAHash = MTSha256(ga)! - return network.request(Api.functions.phone.requestCall(flags: 0, userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer))) + return network.request(Api.functions.phone.requestCall(flags: 0, userId: inputUser, randomId: Int32(bitPattern: arc4random()), gAHash: Buffer(data: gAHash), protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))) |> map { result -> RequestCallSessionResult in switch result { case let .phoneCall(phoneCall, _): @@ -960,8 +961,8 @@ private func requestCallSession(postbox: Postbox, network: Network, peerId: Peer } } -private func confirmCallSession(network: Network, stableId: CallSessionStableId, accessHash: Int64, gA: Data, keyFingerprint: Int64, maxLayer: Int32) -> Signal { - return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(id: stableId, accessHash: accessHash), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer))) +private func confirmCallSession(network: Network, stableId: CallSessionStableId, accessHash: Int64, gA: Data, keyFingerprint: Int64, maxLayer: Int32, versions: [String]) -> Signal { + return network.request(Api.functions.phone.confirmCall(peer: Api.InputPhoneCall.inputPhoneCall(id: stableId, accessHash: accessHash), gA: Buffer(data: gA), keyFingerprint: keyFingerprint, protocol: .phoneCallProtocol(flags: (1 << 0) | (1 << 1), minLayer: minLayer, maxLayer: maxLayer, libraryVersions: versions))) |> map(Optional.init) |> `catch` { _ -> Signal in return .single(nil) diff --git a/submodules/TelegramCore/Sources/LoadedStickerPack.swift b/submodules/TelegramCore/Sources/LoadedStickerPack.swift index 5a657b13b1..d19b4ab1f5 100644 --- a/submodules/TelegramCore/Sources/LoadedStickerPack.swift +++ b/submodules/TelegramCore/Sources/LoadedStickerPack.swift @@ -18,6 +18,8 @@ extension StickerPackReference { return .inputStickerSetShortName(shortName: name) case .animatedEmoji: return .inputStickerSetAnimatedEmoji + case .dice: + return .inputStickerSetDice } } } diff --git a/submodules/TelegramCore/Sources/Network.swift b/submodules/TelegramCore/Sources/Network.swift index 24b84d3fff..5a7d148b23 100644 --- a/submodules/TelegramCore/Sources/Network.swift +++ b/submodules/TelegramCore/Sources/Network.swift @@ -403,16 +403,18 @@ public struct NetworkInitializationArguments { public let languagesCategory: String public let appVersion: String public let voipMaxLayer: Int32 + public let voipVersions: [String] public let appData: Signal public let autolockDeadine: Signal public let encryptionProvider: EncryptionProvider - public init(apiId: Int32, apiHash: String, languagesCategory: String, appVersion: String, voipMaxLayer: Int32, appData: Signal, autolockDeadine: Signal, encryptionProvider: EncryptionProvider) { + public init(apiId: Int32, apiHash: String, languagesCategory: String, appVersion: String, voipMaxLayer: Int32, voipVersions: [String], appData: Signal, autolockDeadine: Signal, encryptionProvider: EncryptionProvider) { self.apiId = apiId self.apiHash = apiHash self.languagesCategory = languagesCategory self.appVersion = appVersion self.voipMaxLayer = voipMaxLayer + self.voipVersions = voipVersions self.appData = appData self.autolockDeadine = autolockDeadine self.encryptionProvider = encryptionProvider diff --git a/submodules/TelegramCore/Sources/StickerSetInstallation.swift b/submodules/TelegramCore/Sources/StickerSetInstallation.swift index f8f84a4e2d..8a6a1eb5d8 100644 --- a/submodules/TelegramCore/Sources/StickerSetInstallation.swift +++ b/submodules/TelegramCore/Sources/StickerSetInstallation.swift @@ -38,6 +38,9 @@ public func requestStickerSet(postbox: Postbox, network: Network, reference: Sti case .animatedEmoji: collectionId = nil input = .inputStickerSetAnimatedEmoji + case .dice: + collectionId = nil + input = .inputStickerSetDice } let localSignal: (ItemCollectionId) -> Signal<(ItemCollectionInfo, [ItemCollectionItem])?, NoError> = { collectionId in diff --git a/submodules/TelegramCore/Sources/SynchronizeSavedStickersOperation.swift b/submodules/TelegramCore/Sources/SynchronizeSavedStickersOperation.swift index f606cfe342..bd53548f3e 100644 --- a/submodules/TelegramCore/Sources/SynchronizeSavedStickersOperation.swift +++ b/submodules/TelegramCore/Sources/SynchronizeSavedStickersOperation.swift @@ -62,7 +62,7 @@ public func addSavedSticker(postbox: Postbox, network: Network, file: TelegramMe if !found { fetchReference = packReference } - case .animatedEmoji: + case .animatedEmoji, .dice: break } if let fetchReference = fetchReference { diff --git a/submodules/TelegramCore/Sources/TelegramMediaFile.swift b/submodules/TelegramCore/Sources/TelegramMediaFile.swift index 51edbe126b..eebae28228 100644 --- a/submodules/TelegramCore/Sources/TelegramMediaFile.swift +++ b/submodules/TelegramCore/Sources/TelegramMediaFile.swift @@ -59,6 +59,8 @@ extension StickerPackReference { self = .name(shortName) case .inputStickerSetAnimatedEmoji: self = .animatedEmoji + case .inputStickerSetDice: + self = .dice } } } diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index 6b6d402bb3..1cb3934f87 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -393,7 +393,7 @@ final class SharedApplicationContext { } } - let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, appData: self.deviceToken.get() + let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, voipVersions: PresentationCallManagerImpl.voipVersions, appData: self.deviceToken.get() |> map { token in let data = buildConfig.bundleData(withAppToken: token, signatureDict: signatureDict) if let data = data, let jsonString = String(data: data, encoding: .utf8) { diff --git a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift index 415104c251..50b8133924 100644 --- a/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift +++ b/submodules/TelegramUI/TelegramUI/NotificationContentContext.swift @@ -154,7 +154,7 @@ public final class NotificationViewControllerImpl { return nil }) - sharedAccountContext = SharedAccountContextImpl(mainWindow: nil, basePath: rootPath, encryptionParameters: ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: self.initializationData.encryptionParameters.0)!, salt: ValueBoxEncryptionParameters.Salt(data: self.initializationData.encryptionParameters.1)!), accountManager: accountManager, appLockContext: appLockContext, applicationBindings: applicationBindings, initialPresentationDataAndSettings: initialPresentationDataAndSettings!, networkArguments: NetworkInitializationArguments(apiId: self.initializationData.apiId, apiHash: self.initializationData.apiHash, languagesCategory: self.initializationData.languagesCategory, appVersion: self.initializationData.appVersion, voipMaxLayer: 0, appData: .single(self.initializationData.bundleData), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), rootPath: rootPath, legacyBasePath: nil, legacyCache: nil, apsNotificationToken: .never(), voipNotificationToken: .never(), setNotificationCall: { _ in }, navigateToChat: { _, _, _ in }) + sharedAccountContext = SharedAccountContextImpl(mainWindow: nil, basePath: rootPath, encryptionParameters: ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: self.initializationData.encryptionParameters.0)!, salt: ValueBoxEncryptionParameters.Salt(data: self.initializationData.encryptionParameters.1)!), accountManager: accountManager, appLockContext: appLockContext, applicationBindings: applicationBindings, initialPresentationDataAndSettings: initialPresentationDataAndSettings!, networkArguments: NetworkInitializationArguments(apiId: self.initializationData.apiId, apiHash: self.initializationData.apiHash, languagesCategory: self.initializationData.languagesCategory, appVersion: self.initializationData.appVersion, voipMaxLayer: 0, voipVersions: [], appData: .single(self.initializationData.bundleData), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), rootPath: rootPath, legacyBasePath: nil, legacyCache: nil, apsNotificationToken: .never(), voipNotificationToken: .never(), setNotificationCall: { _ in }, navigateToChat: { _, _, _ in }) presentationDataPromise.set(sharedAccountContext!.presentationData) } diff --git a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift index 831d15766c..91c4c09e33 100644 --- a/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift +++ b/submodules/TelegramUI/TelegramUI/ShareExtensionContext.swift @@ -192,7 +192,7 @@ public class ShareRootControllerImpl { return nil }) - let sharedContext = SharedAccountContextImpl(mainWindow: nil, basePath: rootPath, encryptionParameters: ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: self.initializationData.encryptionParameters.0)!, salt: ValueBoxEncryptionParameters.Salt(data: self.initializationData.encryptionParameters.1)!), accountManager: accountManager, appLockContext: appLockContext, applicationBindings: applicationBindings, initialPresentationDataAndSettings: initialPresentationDataAndSettings!, networkArguments: NetworkInitializationArguments(apiId: self.initializationData.apiId, apiHash: self.initializationData.apiHash, languagesCategory: self.initializationData.languagesCategory, appVersion: self.initializationData.appVersion, voipMaxLayer: 0, appData: .single(self.initializationData.bundleData), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), rootPath: rootPath, legacyBasePath: nil, legacyCache: nil, apsNotificationToken: .never(), voipNotificationToken: .never(), setNotificationCall: { _ in }, navigateToChat: { _, _, _ in }) + let sharedContext = SharedAccountContextImpl(mainWindow: nil, basePath: rootPath, encryptionParameters: ValueBoxEncryptionParameters(forceEncryptionIfNoSet: false, key: ValueBoxEncryptionParameters.Key(data: self.initializationData.encryptionParameters.0)!, salt: ValueBoxEncryptionParameters.Salt(data: self.initializationData.encryptionParameters.1)!), accountManager: accountManager, appLockContext: appLockContext, applicationBindings: applicationBindings, initialPresentationDataAndSettings: initialPresentationDataAndSettings!, networkArguments: NetworkInitializationArguments(apiId: self.initializationData.apiId, apiHash: self.initializationData.apiHash, languagesCategory: self.initializationData.languagesCategory, appVersion: self.initializationData.appVersion, voipMaxLayer: 0, voipVersions: [], appData: .single(self.initializationData.bundleData), autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()), rootPath: rootPath, legacyBasePath: nil, legacyCache: nil, apsNotificationToken: .never(), voipNotificationToken: .never(), setNotificationCall: { _ in }, navigateToChat: { _, _, _ in }) presentationDataPromise.set(sharedContext.presentationData) internalContext = InternalContext(sharedContext: sharedContext) globalInternalContext = internalContext diff --git a/submodules/TelegramVoip/Sources/OngoingCallContext.swift b/submodules/TelegramVoip/Sources/OngoingCallContext.swift index 210144168a..016897e9fe 100644 --- a/submodules/TelegramVoip/Sources/OngoingCallContext.swift +++ b/submodules/TelegramVoip/Sources/OngoingCallContext.swift @@ -173,6 +173,10 @@ public final class OngoingCallContext { return OngoingCallThreadLocalContext.maxLayer() } + public static var version: String { + return OngoingCallThreadLocalContext.version()! + } + public init(account: Account, callSessionManager: CallSessionManager, internalId: CallSessionInternalId, proxyServer: ProxyServerSettings?, initialNetworkType: NetworkType, updatedNetworkType: Signal, serializedData: String?, dataSaving: VoiceCallDataSaving, derivedState: VoipDerivedState) { let _ = setupLogs OngoingCallThreadLocalContext.applyServerConfig(serializedData) diff --git a/submodules/libtgvoip/OngoingCallThreadLocalContext.h b/submodules/libtgvoip/OngoingCallThreadLocalContext.h index 374c9dc6a2..674a80d80e 100644 --- a/submodules/libtgvoip/OngoingCallThreadLocalContext.h +++ b/submodules/libtgvoip/OngoingCallThreadLocalContext.h @@ -59,6 +59,7 @@ typedef NS_ENUM(int32_t, OngoingCallDataSaving) { + (void)setupLoggingFunction:(void (* _Nullable)(NSString * _Nullable))loggingFunction; + (void)applyServerConfig:(NSString * _Nullable)data; + (int32_t)maxLayer; ++ (NSString *)version; @property (nonatomic, copy) void (^ _Nullable stateChanged)(OngoingCallState); @property (nonatomic, copy) void (^ _Nullable signalBarsChanged)(int32_t); diff --git a/submodules/libtgvoip/OngoingCallThreadLocalContext.mm b/submodules/libtgvoip/OngoingCallThreadLocalContext.mm index c98bcf146f..125a7b849a 100644 --- a/submodules/libtgvoip/OngoingCallThreadLocalContext.mm +++ b/submodules/libtgvoip/OngoingCallThreadLocalContext.mm @@ -218,6 +218,10 @@ static int callControllerDataSavingForType(OngoingCallDataSaving type) { return tgvoip::VoIPController::GetConnectionMaxLayer(); } ++ (NSString *)version { + return [NSString stringWithUTF8String:tgvoip::VoIPController::GetVersion()]; +} + - (instancetype _Nonnull)initWithQueue:(id _Nonnull)queue proxy:(VoipProxyServer * _Nullable)proxy networkType:(OngoingCallNetworkType)networkType dataSaving:(OngoingCallDataSaving)dataSaving derivedState:(NSData * _Nonnull)derivedState { self = [super init]; if (self != nil) {