mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Use enableSystemIntegration in notification service extension
This commit is contained in:
parent
f735b1a96c
commit
96b6864a51
@ -628,6 +628,13 @@ private final class NotificationServiceHandler {
|
||||
isLockedMessage = nil
|
||||
}
|
||||
|
||||
let incomingCallMessage: String
|
||||
if let notificationsPresentationData = try? Data(contentsOf: URL(fileURLWithPath: notificationsPresentationDataPath(rootPath: rootPath))), let notificationsPresentationDataValue = try? JSONDecoder().decode(NotificationsPresentationData.self, from: notificationsPresentationData) {
|
||||
incomingCallMessage = notificationsPresentationDataValue.incomingCallString
|
||||
} else {
|
||||
incomingCallMessage = "is calling you"
|
||||
}
|
||||
|
||||
Logger.shared.log("NotificationService \(episode)", "Begin processing payload \(payload)")
|
||||
|
||||
guard var encryptedPayload = payload["p"] as? String else {
|
||||
@ -646,7 +653,7 @@ private final class NotificationServiceHandler {
|
||||
|
||||
let _ = (combineLatest(queue: self.queue,
|
||||
self.accountManager.accountRecords(),
|
||||
self.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings])
|
||||
self.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings, ApplicationSpecificSharedDataKeys.voiceCallSettings])
|
||||
)
|
||||
|> take(1)
|
||||
|> deliverOn(self.queue)).start(next: { [weak self] records, sharedData in
|
||||
@ -671,6 +678,13 @@ private final class NotificationServiceHandler {
|
||||
|
||||
let inAppNotificationSettings = sharedData.entries[ApplicationSpecificSharedDataKeys.inAppNotificationSettings]?.get(InAppNotificationSettings.self) ?? InAppNotificationSettings.defaultSettings
|
||||
|
||||
let voiceCallSettings: VoiceCallSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.voiceCallSettings]?.get(VoiceCallSettings.self) {
|
||||
voiceCallSettings = value
|
||||
} else {
|
||||
voiceCallSettings = VoiceCallSettings.defaultSettings
|
||||
}
|
||||
|
||||
guard let strongSelf = self, let recordId = recordId else {
|
||||
Logger.shared.log("NotificationService \(episode)", "Couldn't find a matching decryption key")
|
||||
|
||||
@ -754,6 +768,7 @@ private final class NotificationServiceHandler {
|
||||
var fromId: PeerId
|
||||
var updates: String
|
||||
var accountId: Int64
|
||||
var peer: EnginePeer?
|
||||
}
|
||||
|
||||
var callData: CallData?
|
||||
@ -782,12 +797,27 @@ 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) {
|
||||
var peer: EnginePeer?
|
||||
|
||||
var updateString = updates
|
||||
updateString = updateString.replacingOccurrences(of: "-", with: "+")
|
||||
updateString = updateString.replacingOccurrences(of: "_", with: "/")
|
||||
while updateString.count % 4 != 0 {
|
||||
updateString.append("=")
|
||||
}
|
||||
if let updateData = Data(base64Encoded: updateString) {
|
||||
if let callUpdate = AccountStateManager.extractIncomingCallUpdate(data: updateData) {
|
||||
peer = callUpdate.peer
|
||||
}
|
||||
}
|
||||
|
||||
callData = CallData(
|
||||
id: callId,
|
||||
accessHash: callAccessHash,
|
||||
fromId: peerId,
|
||||
updates: updates,
|
||||
accountId: recordId.int64
|
||||
accountId: recordId.int64,
|
||||
peer: peer
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -937,17 +967,27 @@ private final class NotificationServiceHandler {
|
||||
"updates": callData.updates,
|
||||
"accountId": "\(callData.accountId)"
|
||||
]
|
||||
|
||||
if #available(iOS 14.5, *), voiceCallSettings.enableSystemIntegration {
|
||||
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
||||
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||
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 {
|
||||
var content = NotificationContent(isLockedMessage: nil)
|
||||
if let peer = callData.peer {
|
||||
content.title = peer.debugDisplayTitle
|
||||
content.body = incomingCallMessage
|
||||
} else {
|
||||
content.body = "Incoming Call"
|
||||
}
|
||||
|
||||
updateCurrentContent(content)
|
||||
completed()
|
||||
}
|
||||
case .logout:
|
||||
|
@ -297,7 +297,15 @@ final class WidgetDataContext {
|
||||
|
||||
self.notificationPresentationDataDisposable = (presentationData
|
||||
|> map { presentationData -> NotificationsPresentationData in
|
||||
return NotificationsPresentationData(applicationLockedMessageString: presentationData.strings.PUSH_LOCKED_MESSAGE("").string)
|
||||
var incomingCallString = presentationData.strings.PUSH_PHONE_CALL_REQUEST("").string
|
||||
if let range = incomingCallString.range(of: "|") {
|
||||
incomingCallString = String(incomingCallString[range.upperBound...])
|
||||
}
|
||||
|
||||
return NotificationsPresentationData(
|
||||
applicationLockedMessageString: presentationData.strings.PUSH_LOCKED_MESSAGE("").string,
|
||||
incomingCallString: incomingCallString
|
||||
)
|
||||
}
|
||||
|> distinctUntilChanged).start(next: { value in
|
||||
let path = notificationsPresentationDataPath(rootPath: basePath)
|
||||
|
Loading…
x
Reference in New Issue
Block a user