mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Pass through voip notifications
This commit is contained in:
parent
11ae567544
commit
f71e94ed9b
@ -12,6 +12,7 @@ import GZip
|
|||||||
import UIKit
|
import UIKit
|
||||||
import Intents
|
import Intents
|
||||||
import PersistentStringHash
|
import PersistentStringHash
|
||||||
|
import CallKit
|
||||||
|
|
||||||
private let queue = Queue()
|
private let queue = Queue()
|
||||||
|
|
||||||
@ -723,6 +724,15 @@ private final class NotificationServiceHandler {
|
|||||||
|
|
||||||
var interactionAuthorId: PeerId?
|
var interactionAuthorId: PeerId?
|
||||||
|
|
||||||
|
struct CallData {
|
||||||
|
var id: Int64
|
||||||
|
var accessHash: Int64
|
||||||
|
var fromId: PeerId
|
||||||
|
var updates: String
|
||||||
|
}
|
||||||
|
|
||||||
|
var callData: CallData?
|
||||||
|
|
||||||
if let messageIdString = payloadJson["msg_id"] as? String {
|
if let messageIdString = payloadJson["msg_id"] as? String {
|
||||||
messageId = Int32(messageIdString)
|
messageId = Int32(messageIdString)
|
||||||
}
|
}
|
||||||
@ -745,16 +755,30 @@ private final class NotificationServiceHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let callIdString = payloadJson["call_id"] as? String, let callAccessHashString = payloadJson["call_ah"] as? String, let peerId = peerId, let updates = payloadJson["updates"] as? String {
|
||||||
|
if let callId = Int64(callIdString), let callAccessHash = Int64(callAccessHashString) {
|
||||||
|
callData = CallData(
|
||||||
|
id: callId,
|
||||||
|
accessHash: callAccessHash,
|
||||||
|
fromId: peerId,
|
||||||
|
updates: updates
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum Action {
|
enum Action {
|
||||||
case logout
|
case logout
|
||||||
case poll(peerId: PeerId, content: NotificationContent)
|
case poll(peerId: PeerId, content: NotificationContent)
|
||||||
case deleteMessage([MessageId])
|
case deleteMessage([MessageId])
|
||||||
case readMessage(MessageId)
|
case readMessage(MessageId)
|
||||||
|
case call(CallData)
|
||||||
}
|
}
|
||||||
|
|
||||||
var action: Action?
|
var action: Action?
|
||||||
|
|
||||||
if let locKey = payloadJson["loc-key"] as? String {
|
if let callData = callData {
|
||||||
|
action = .call(callData)
|
||||||
|
} else if let locKey = payloadJson["loc-key"] as? String {
|
||||||
switch locKey {
|
switch locKey {
|
||||||
case "SESSION_REVOKE":
|
case "SESSION_REVOKE":
|
||||||
action = .logout
|
action = .logout
|
||||||
@ -879,8 +903,31 @@ private final class NotificationServiceHandler {
|
|||||||
|
|
||||||
if let action = action {
|
if let action = action {
|
||||||
switch action {
|
switch action {
|
||||||
|
case let .call(callData):
|
||||||
|
let voipPayload: [AnyHashable: Any] = [
|
||||||
|
"call_id": "\(callData.id)",
|
||||||
|
"call_ah": "\(callData.accessHash)",
|
||||||
|
"from_id": "\(callData.fromId.id._internalGetInt64Value())",
|
||||||
|
"updates": callData.updates
|
||||||
|
]
|
||||||
|
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
||||||
|
let content = NotificationContent()
|
||||||
|
updateCurrentContent(content)
|
||||||
|
|
||||||
|
if #available(iOS 14.5, *) {
|
||||||
|
CXProvider.reportNewIncomingVoIPPushPayload(voipPayload, completion: { error in
|
||||||
|
Logger.shared.log("NotificationService \(episode)", "Did report voip notification, error: \(String(describing: error))")
|
||||||
|
|
||||||
|
completed()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
completed()
|
||||||
|
}
|
||||||
case .logout:
|
case .logout:
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will logout")
|
Logger.shared.log("NotificationService \(episode)", "Will logout")
|
||||||
|
|
||||||
|
let content = NotificationContent()
|
||||||
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
case let .poll(peerId, initialContent):
|
case let .poll(peerId, initialContent):
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will poll")
|
Logger.shared.log("NotificationService \(episode)", "Will poll")
|
||||||
@ -890,6 +937,9 @@ private final class NotificationServiceHandler {
|
|||||||
|
|
||||||
queue.async {
|
queue.async {
|
||||||
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
guard let strongSelf = self, let stateManager = strongSelf.stateManager else {
|
||||||
|
|
||||||
|
let content = NotificationContent()
|
||||||
|
updateCurrentContent(content)
|
||||||
completed()
|
completed()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user