diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index e2ff733bca..0abf31498d 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -1432,8 +1432,20 @@ private func extractAccountManagerState(records: AccountRecordsView Void) { + self.pushRegistryImpl(registry, didReceiveIncomingPushWith: payload, for: type, completion: completion) + } + public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) { + self.pushRegistryImpl(registry, didReceiveIncomingPushWith: payload, for: type, completion: {}) + } + + private func pushRegistryImpl(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) { + Logger.shared.log("App \(self.episodeId) PushRegistry", "pushRegistry didReceiveIncomingPushWith") + guard var encryptedPayload = payload.dictionaryPayload["p"] as? String else { + Logger.shared.log("App \(self.episodeId) PushRegistry", "encryptedPayload is nil") + completion() return } encryptedPayload = encryptedPayload.replacingOccurrences(of: "-", with: "+") @@ -1442,13 +1454,18 @@ private func extractAccountManagerState(records: AccountRecordsView take(1) - |> mapToSignal { sharedApplicationContext -> Signal<[(Account, MasterNotificationKey)], NoError> in - sharedApplicationContextValue = sharedApplicationContext - - return sharedApplicationContext.sharedContext.activeAccounts - |> take(1) - |> mapToSignal { activeAccounts -> Signal<[(Account, MasterNotificationKey)], NoError> in - return combineLatest(activeAccounts.accounts.map { account -> Signal<(Account, MasterNotificationKey), NoError> in - return masterNotificationsKey(account: account.1, ignoreDisabled: true) - |> map { key -> (Account, MasterNotificationKey) in - return (account.1, key) - } - }) - } - } - - let _ = accountsAndKeys.start(next: { accountsAndKeys in - for (account, key) in accountsAndKeys { - if let decryptedData = decryptedNotificationPayload(key: key, data: data) { - accountAndDecryptedPayload = (account, decryptedData) - break - } - } - semaphore.signal() - }) - semaphore.wait() - - if let sharedApplicationContextValue = sharedApplicationContextValue, let (account, decryptedData) = accountAndDecryptedPayload { - if let decryptedDict = (try? JSONSerialization.jsonObject(with: decryptedData, options: [])) as? [AnyHashable: Any] { - if var updateString = decryptedDict["updates"] as? String { - updateString = updateString.replacingOccurrences(of: "-", with: "+") - updateString = updateString.replacingOccurrences(of: "_", with: "/") - while updateString.count % 4 != 0 { - updateString.append("=") - } - if let updateData = Data(base64Encoded: updateString) { - var result: (CallSessionRingingState, CallSession)? - let semaphore = DispatchSemaphore(value: 0) - account.stateManager.processIncomingCallUpdate(data: updateData, completion: { ringingState in - result = ringingState - semaphore.signal() - }) - semaphore.wait() - - if let (ringingState, callSession) = result { - (sharedApplicationContextValue.sharedContext.callManager as? PresentationCallManagerImpl)?.injectRingingStateSynchronously(account: account, ringingState: ringingState, callSession: callSession) - } - } - } - } - }*/ let _ = (self.sharedContextPromise.get() |> take(1) @@ -1623,10 +1596,14 @@ private func extractAccountManagerState(records: AccountRecordsView