mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +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
|
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)")
|
Logger.shared.log("NotificationService \(episode)", "Begin processing payload \(payload)")
|
||||||
|
|
||||||
guard var encryptedPayload = payload["p"] as? String else {
|
guard var encryptedPayload = payload["p"] as? String else {
|
||||||
@ -646,7 +653,7 @@ private final class NotificationServiceHandler {
|
|||||||
|
|
||||||
let _ = (combineLatest(queue: self.queue,
|
let _ = (combineLatest(queue: self.queue,
|
||||||
self.accountManager.accountRecords(),
|
self.accountManager.accountRecords(),
|
||||||
self.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings])
|
self.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.inAppNotificationSettings, ApplicationSpecificSharedDataKeys.voiceCallSettings])
|
||||||
)
|
)
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> deliverOn(self.queue)).start(next: { [weak self] records, sharedData in
|
|> 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 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 {
|
guard let strongSelf = self, let recordId = recordId else {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Couldn't find a matching decryption key")
|
Logger.shared.log("NotificationService \(episode)", "Couldn't find a matching decryption key")
|
||||||
|
|
||||||
@ -754,6 +768,7 @@ private final class NotificationServiceHandler {
|
|||||||
var fromId: PeerId
|
var fromId: PeerId
|
||||||
var updates: String
|
var updates: String
|
||||||
var accountId: Int64
|
var accountId: Int64
|
||||||
|
var peer: EnginePeer?
|
||||||
}
|
}
|
||||||
|
|
||||||
var callData: CallData?
|
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 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) {
|
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(
|
callData = CallData(
|
||||||
id: callId,
|
id: callId,
|
||||||
accessHash: callAccessHash,
|
accessHash: callAccessHash,
|
||||||
fromId: peerId,
|
fromId: peerId,
|
||||||
updates: updates,
|
updates: updates,
|
||||||
accountId: recordId.int64
|
accountId: recordId.int64,
|
||||||
|
peer: peer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -937,17 +967,27 @@ private final class NotificationServiceHandler {
|
|||||||
"updates": callData.updates,
|
"updates": callData.updates,
|
||||||
"accountId": "\(callData.accountId)"
|
"accountId": "\(callData.accountId)"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if #available(iOS 14.5, *), voiceCallSettings.enableSystemIntegration {
|
||||||
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
Logger.shared.log("NotificationService \(episode)", "Will report voip notification")
|
||||||
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
let content = NotificationContent(isLockedMessage: isLockedMessage)
|
||||||
updateCurrentContent(content)
|
updateCurrentContent(content)
|
||||||
|
|
||||||
if #available(iOS 14.5, *) {
|
|
||||||
CXProvider.reportNewIncomingVoIPPushPayload(voipPayload, completion: { error in
|
CXProvider.reportNewIncomingVoIPPushPayload(voipPayload, completion: { error in
|
||||||
Logger.shared.log("NotificationService \(episode)", "Did report voip notification, error: \(String(describing: error))")
|
Logger.shared.log("NotificationService \(episode)", "Did report voip notification, error: \(String(describing: error))")
|
||||||
|
|
||||||
completed()
|
completed()
|
||||||
})
|
})
|
||||||
} else {
|
} 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()
|
completed()
|
||||||
}
|
}
|
||||||
case .logout:
|
case .logout:
|
||||||
|
@ -297,7 +297,15 @@ final class WidgetDataContext {
|
|||||||
|
|
||||||
self.notificationPresentationDataDisposable = (presentationData
|
self.notificationPresentationDataDisposable = (presentationData
|
||||||
|> map { presentationData -> NotificationsPresentationData in
|
|> 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
|
|> distinctUntilChanged).start(next: { value in
|
||||||
let path = notificationsPresentationDataPath(rootPath: basePath)
|
let path = notificationsPresentationDataPath(rootPath: basePath)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user