|
|
|
@ -96,17 +96,18 @@ extension UserNotificationPresenterAdaptee: NotificationPresenterAdaptee {
|
|
|
|
|
let content = UNMutableNotificationContent()
|
|
|
|
|
content.categoryIdentifier = category.identifier
|
|
|
|
|
content.userInfo = userInfo
|
|
|
|
|
let isReplacingNotification = replacingIdentifier != nil
|
|
|
|
|
var isBackgroudPoll = false
|
|
|
|
|
if let threadIdentifier = userInfo[AppNotificationUserInfoKey.threadId] as? String {
|
|
|
|
|
content.threadIdentifier = threadIdentifier
|
|
|
|
|
isBackgroudPoll = replacingIdentifier == threadIdentifier
|
|
|
|
|
}
|
|
|
|
|
let isAppActive = UIApplication.shared.applicationState == .active
|
|
|
|
|
if let sound = sound, sound != OWSSound.none {
|
|
|
|
|
content.sound = sound.notificationSound(isQuiet: isAppActive)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var notificationIdentifier: String = UUID().uuidString
|
|
|
|
|
if let replacingIdentifier = replacingIdentifier {
|
|
|
|
|
notificationIdentifier = replacingIdentifier
|
|
|
|
|
Logger.debug("replacing notification with identifier: \(notificationIdentifier)")
|
|
|
|
|
cancelNotification(identifier: notificationIdentifier)
|
|
|
|
|
}
|
|
|
|
|
let notificationIdentifier = isReplacingNotification ? replacingIdentifier! : UUID().uuidString
|
|
|
|
|
|
|
|
|
|
if shouldPresentNotification(category: category, userInfo: userInfo) {
|
|
|
|
|
if let displayableTitle = title?.filterForDisplay {
|
|
|
|
@ -120,9 +121,25 @@ extension UserNotificationPresenterAdaptee: NotificationPresenterAdaptee {
|
|
|
|
|
Logger.debug("supressing notification body")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let request = UNNotificationRequest(identifier: notificationIdentifier, content: content, trigger: nil)
|
|
|
|
|
let trigger: UNNotificationTrigger?
|
|
|
|
|
if isBackgroudPoll {
|
|
|
|
|
trigger = UNTimeIntervalNotificationTrigger(timeInterval: kNotificationDelayForBackgroumdPoll, repeats: false)
|
|
|
|
|
let numberOfNotifications: Int
|
|
|
|
|
if let lastRequest = notifications[notificationIdentifier], let counter = lastRequest.content.userInfo[AppNotificationUserInfoKey.threadNotificationCounter] as? Int {
|
|
|
|
|
numberOfNotifications = counter + 1
|
|
|
|
|
content.body = String(format: NotificationStrings.incomingCollapsedMessagesBody, "\(numberOfNotifications)")
|
|
|
|
|
} else {
|
|
|
|
|
numberOfNotifications = 1
|
|
|
|
|
}
|
|
|
|
|
content.userInfo[AppNotificationUserInfoKey.threadNotificationCounter] = numberOfNotifications
|
|
|
|
|
} else {
|
|
|
|
|
trigger = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let request = UNNotificationRequest(identifier: notificationIdentifier, content: content, trigger: trigger)
|
|
|
|
|
|
|
|
|
|
Logger.debug("presenting notification with identifier: \(notificationIdentifier)")
|
|
|
|
|
if isReplacingNotification { cancelNotification(identifier: notificationIdentifier) }
|
|
|
|
|
notificationCenter.add(request)
|
|
|
|
|
notifications[notificationIdentifier] = request
|
|
|
|
|
}
|
|
|
|
|