diff --git a/Telegram/NotificationService/Sources/NotificationService.swift b/Telegram/NotificationService/Sources/NotificationService.swift index 6f964ca8e0..ca4adac219 100644 --- a/Telegram/NotificationService/Sources/NotificationService.swift +++ b/Telegram/NotificationService/Sources/NotificationService.swift @@ -627,6 +627,13 @@ private final class NotificationServiceHandler { } else { 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)") @@ -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 @@ -670,6 +677,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)" ] - Logger.shared.log("NotificationService \(episode)", "Will report voip notification") - let content = NotificationContent(isLockedMessage: isLockedMessage) - updateCurrentContent(content) - if #available(iOS 14.5, *) { + if #available(iOS 14.5, *), voiceCallSettings.enableSystemIntegration { + Logger.shared.log("NotificationService \(episode)", "Will report voip notification") + let content = NotificationContent(isLockedMessage: isLockedMessage) + updateCurrentContent(content) + 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: diff --git a/submodules/TelegramUI/Sources/WidgetDataContext.swift b/submodules/TelegramUI/Sources/WidgetDataContext.swift index f172bb7ff6..2877f3ae6a 100644 --- a/submodules/TelegramUI/Sources/WidgetDataContext.swift +++ b/submodules/TelegramUI/Sources/WidgetDataContext.swift @@ -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)