Add a wait time of up to 3 second inside the app extension, then iterate to try and receive the NOTIFY required for imdn sending

This commit is contained in:
QuentinA 2026-03-06 12:49:48 +01:00 committed by Quentin Arguillere
parent b8efad4980
commit fa9be23c2d

View file

@ -89,7 +89,7 @@ class NotificationService: UNNotificationServiceExtension {
}
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let timeStart = Date.now
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
@ -172,6 +172,7 @@ class NotificationService: UNNotificationServiceExtension {
let message = lc!.getNewMessageFromCallid(callId: callId)
if let message = message {
let nilParams: ConferenceParams? = nil
if let peerAddr = message.peerAddr
, let chatroom = lc!.searchChatRoom(params: nilParams, localAddr: nil, remoteAddr: peerAddr, participants: nil), chatroom.muted {
@ -188,7 +189,6 @@ class NotificationService: UNNotificationServiceExtension {
bestAttemptContent.badge = badge
}
stopCore()
bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "msg.caf"))
bestAttemptContent.title = String(localized: "notification_chat_message_received_title")
if let subtitle = msgData?.subtitle {
@ -204,12 +204,18 @@ class NotificationService: UNNotificationServiceExtension {
bestAttemptContent.userInfo.updateValue(msgData?.from as Any, forKey: "from")
bestAttemptContent.userInfo.updateValue(msgData?.peerAddr as Any, forKey: "peer_addr")
bestAttemptContent.userInfo.updateValue(msgData?.localAddr as Any, forKey: "local_addr")
// start remaining time count 25 instead of 30 to make sure we keep at least 5 seconds to finish the message processing
let remainingTime = max(0, 25 - Date.now.timeIntervalSince(timeStart))
DispatchQueue.main.asyncAfter(deadline: .now() + min(3, remainingTime)) {
self.lc?.iterate()
self.stopCore()
if message.reactionContent != " " {
contentHandler(bestAttemptContent)
} else {
contentHandler(UNNotificationContent())
}
}
return
} else {
Log.info("Message not found for callid ["+callId+"]")