Fixed a bug where the "default" notification sound wouldn't be used in the foreground

pull/670/head
Morgan Pretty 2 years ago
parent fc949a9882
commit 6a32fbaf83

@ -230,15 +230,21 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
threadId: thread.id, threadId: thread.id,
threadVariant: thread.variant threadVariant: thread.variant
) )
let fallbackSound: Preferences.Sound = db[.defaultNotificationSound]
.defaulting(to: Preferences.Sound.defaultNotificationSound)
DispatchQueue.main.async { DispatchQueue.main.async {
let sound: Preferences.Sound? = self.requestSound(
thread: thread,
fallbackSound: fallbackSound
)
notificationBody = MentionUtilities.highlightMentions( notificationBody = MentionUtilities.highlightMentions(
in: (notificationBody ?? ""), in: (notificationBody ?? ""),
threadVariant: thread.variant, threadVariant: thread.variant,
currentUserPublicKey: userPublicKey, currentUserPublicKey: userPublicKey,
currentUserBlindedPublicKey: userBlindedKey currentUserBlindedPublicKey: userBlindedKey
) )
let sound: Preferences.Sound? = self.requestSound(thread: thread)
self.adaptee.notify( self.adaptee.notify(
category: category, category: category,
@ -287,9 +293,14 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
) )
) )
} }
let fallbackSound: Preferences.Sound = db[.defaultNotificationSound]
.defaulting(to: Preferences.Sound.defaultNotificationSound)
DispatchQueue.main.async { DispatchQueue.main.async {
let sound = self.requestSound(thread: thread) let sound = self.requestSound(
thread: thread,
fallbackSound: fallbackSound
)
self.adaptee.notify( self.adaptee.notify(
category: category, category: category,
@ -331,9 +342,14 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
let userInfo = [ let userInfo = [
AppNotificationUserInfoKey.threadId: thread.id AppNotificationUserInfoKey.threadId: thread.id
] ]
let fallbackSound: Preferences.Sound = db[.defaultNotificationSound]
.defaulting(to: Preferences.Sound.defaultNotificationSound)
DispatchQueue.main.async { DispatchQueue.main.async {
let sound: Preferences.Sound? = self.requestSound(thread: thread) let sound: Preferences.Sound? = self.requestSound(
thread: thread,
fallbackSound: fallbackSound
)
self.adaptee.notify( self.adaptee.notify(
category: .errorMessage, category: .errorMessage,
@ -366,12 +382,12 @@ public class NotificationPresenter: NSObject, NotificationsProtocol {
var mostRecentNotifications = TruncatedList<UInt64>(maxLength: kAudioNotificationsThrottleCount) var mostRecentNotifications = TruncatedList<UInt64>(maxLength: kAudioNotificationsThrottleCount)
private func requestSound(thread: SessionThread) -> Preferences.Sound? { private func requestSound(thread: SessionThread, fallbackSound: Preferences.Sound) -> Preferences.Sound? {
guard checkIfShouldPlaySound() else { guard checkIfShouldPlaySound() else {
return nil return nil
} }
return thread.notificationSound return (thread.notificationSound ?? fallbackSound)
} }
private func checkIfShouldPlaySound() -> Bool { private func checkIfShouldPlaySound() -> Bool {

Loading…
Cancel
Save