mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix call reporting
This commit is contained in:
parent
5b285a8b66
commit
78f4adf784
@ -729,6 +729,7 @@ private final class NotificationServiceHandler {
|
||||
var accessHash: Int64
|
||||
var fromId: PeerId
|
||||
var updates: String
|
||||
var accountId: Int64
|
||||
}
|
||||
|
||||
var callData: CallData?
|
||||
@ -761,7 +762,8 @@ private final class NotificationServiceHandler {
|
||||
id: callId,
|
||||
accessHash: callAccessHash,
|
||||
fromId: peerId,
|
||||
updates: updates
|
||||
updates: updates,
|
||||
accountId: recordId.int64
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -908,7 +910,8 @@ private final class NotificationServiceHandler {
|
||||
"call_id": "\(callData.id)",
|
||||
"call_ah": "\(callData.accessHash)",
|
||||
"from_id": "\(callData.fromId.id._internalGetInt64Value())",
|
||||
"updates": callData.updates
|
||||
"updates": callData.updates,
|
||||
"accountId": "\(callData.accountId)"
|
||||
]
|
||||
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
||||
let content = NotificationContent()
|
||||
|
@ -9,7 +9,13 @@ import SwiftSignalKit
|
||||
import AppBundle
|
||||
import AccountContext
|
||||
|
||||
private var sharedProviderDelegate: AnyObject?
|
||||
private let sharedProviderDelegate: AnyObject? = {
|
||||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
return CallKitProviderDelegate()
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
|
||||
public final class CallKitIntegration {
|
||||
public static var isAvailable: Bool {
|
||||
@ -42,9 +48,6 @@ public final class CallKitIntegration {
|
||||
audioSessionActivationChanged: @escaping (Bool) -> Void
|
||||
) {
|
||||
if #available(iOSApplicationExtension 10.0, iOS 10.0, *) {
|
||||
if sharedProviderDelegate == nil {
|
||||
sharedProviderDelegate = CallKitProviderDelegate()
|
||||
}
|
||||
(sharedProviderDelegate as? CallKitProviderDelegate)?.setup(audioSessionActivePromise: self.audioSessionActivePromise, startCall: startCall, answerCall: answerCall, endCall: endCall, setCallMuted: setCallMuted, audioSessionActivationChanged: audioSessionActivationChanged)
|
||||
}
|
||||
}
|
||||
|
@ -711,6 +711,13 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
telegramUIDeclareEncodables()
|
||||
initializeAccountManagement()
|
||||
|
||||
let pushRegistry = PKPushRegistry(queue: .main)
|
||||
if #available(iOS 9.0, *) {
|
||||
pushRegistry.desiredPushTypes = Set([.voIP])
|
||||
}
|
||||
self.pushRegistry = pushRegistry
|
||||
pushRegistry.delegate = self
|
||||
|
||||
self.accountManagerState = extractAccountManagerState(records: accountManager._internalAccountRecordsSync())
|
||||
let _ = (accountManager.accountRecords()
|
||||
|> deliverOnMainQueue).start(next: { view in
|
||||
@ -1167,13 +1174,6 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}
|
||||
})
|
||||
|
||||
let pushRegistry = PKPushRegistry(queue: .main)
|
||||
if #available(iOS 9.0, *) {
|
||||
pushRegistry.desiredPushTypes = Set([.voIP])
|
||||
}
|
||||
self.pushRegistry = pushRegistry
|
||||
pushRegistry.delegate = self
|
||||
|
||||
self.resetBadge()
|
||||
|
||||
if #available(iOS 9.1, *) {
|
||||
@ -1433,16 +1433,25 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}
|
||||
|
||||
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "pushRegistry didReceiveIncomingPushWith \(payload.dictionaryPayload)")
|
||||
|
||||
self.pushRegistryImpl(registry, didReceiveIncomingPushWith: payload, for: type, completion: completion)
|
||||
}
|
||||
|
||||
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "pushRegistry didReceiveIncomingPushWith \(payload.dictionaryPayload)")
|
||||
|
||||
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")
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "pushRegistry processing push notification")
|
||||
|
||||
let decryptedPayloadAndAccountId: ([AnyHashable: Any], AccountRecordId)?
|
||||
|
||||
if let accountIdString = payload.dictionaryPayload["accountId"] as? String, let accountId = Int64(accountIdString) {
|
||||
decryptedPayloadAndAccountId = (payload.dictionaryPayload, AccountRecordId(rawValue: accountId))
|
||||
} else {
|
||||
guard var encryptedPayload = payload.dictionaryPayload["p"] as? String else {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "encryptedPayload is nil")
|
||||
completion()
|
||||
@ -1490,11 +1499,21 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
completion()
|
||||
return
|
||||
}
|
||||
guard let payloadJson = try? JSONSerialization.jsonObject(with: decryptedPayload, options: []) as? [String: Any] else {
|
||||
guard let payloadJson = try? JSONSerialization.jsonObject(with: decryptedPayload, options: []) as? [AnyHashable: Any] else {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "Couldn't decode payload json")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
decryptedPayloadAndAccountId = (payloadJson, accountId)
|
||||
}
|
||||
|
||||
guard let (payloadJson, accountId) = decryptedPayloadAndAccountId else {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "decryptedPayloadAndAccountId is nil")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
|
||||
guard var updateString = payloadJson["updates"] as? String else {
|
||||
Logger.shared.log("App \(self.episodeId) PushRegistry", "updates is nil")
|
||||
completion()
|
||||
@ -1544,55 +1563,22 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}
|
||||
)
|
||||
|
||||
let _ = accountId
|
||||
|
||||
let _ = (self.sharedContextPromise.get()
|
||||
|> take(1)
|
||||
|> deliverOnMainQueue).start(next: { sharedApplicationContext in
|
||||
if var encryptedPayload = payload.dictionaryPayload["p"] as? String {
|
||||
encryptedPayload = encryptedPayload.replacingOccurrences(of: "-", with: "+")
|
||||
encryptedPayload = encryptedPayload.replacingOccurrences(of: "_", with: "/")
|
||||
while encryptedPayload.count % 4 != 0 {
|
||||
encryptedPayload.append("=")
|
||||
}
|
||||
if let data = Data(base64Encoded: encryptedPayload) {
|
||||
let _ = (sharedApplicationContext.sharedContext.activeAccountContexts
|
||||
|> take(1)
|
||||
|> mapToSignal { activeAccounts -> Signal<[(Account, MasterNotificationKey)], NoError> in
|
||||
return combineLatest(activeAccounts.accounts.map { context -> Signal<(Account, MasterNotificationKey), NoError> in
|
||||
return masterNotificationsKey(account: context.1.account, ignoreDisabled: true)
|
||||
|> map { key -> (Account, MasterNotificationKey) in
|
||||
return (context.1.account, key)
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { activeAccounts in
|
||||
for (_, context, _) in activeAccounts.accounts {
|
||||
if context.account.id == accountId {
|
||||
context.account.stateManager.processIncomingCallUpdate(data: updateData, completion: { _ in
|
||||
})
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { accountsAndKeys in
|
||||
var accountAndDecryptedPayload: (Account, Data)?
|
||||
for (account, key) in accountsAndKeys {
|
||||
if let decryptedData = decryptedNotificationPayload(key: key, data: data) {
|
||||
accountAndDecryptedPayload = (account, decryptedData)
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if 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) {
|
||||
account.stateManager.processIncomingCallUpdate(data: updateData, completion: { _ in
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
sharedApplicationContext.wakeupManager.allowBackgroundTimeExtension(timeout: 2.0)
|
||||
|
||||
if case PKPushType.voIP = type {
|
||||
|
@ -172,6 +172,14 @@ public final class SharedNotificationManager {
|
||||
}
|
||||
var decryptedNotifications: [(Account, Bool, [AnyHashable: Any])] = []
|
||||
for notification in self.notifications {
|
||||
if let accountIdString = notification.dict["accountId"] as? String, let accountId = Int64(accountIdString) {
|
||||
inner: for (account, isCurrent, _) in accountsAndKeys {
|
||||
if account.id.int64 == accountId {
|
||||
decryptedNotifications.append((account, isCurrent, notification.dict))
|
||||
break inner
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if var encryptedPayload = notification.dict["p"] as? String {
|
||||
encryptedPayload = encryptedPayload.replacingOccurrences(of: "-", with: "+")
|
||||
encryptedPayload = encryptedPayload.replacingOccurrences(of: "_", with: "/")
|
||||
@ -190,6 +198,7 @@ public final class SharedNotificationManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.notifications.removeAll()
|
||||
|
||||
for (account, isCurrent, payload) in decryptedNotifications {
|
||||
|
Loading…
x
Reference in New Issue
Block a user