diff --git a/ElementX/Sources/Application/Settings/AppSettings.swift b/ElementX/Sources/Application/Settings/AppSettings.swift index 02fbfc4a1..8a707057a 100644 --- a/ElementX/Sources/Application/Settings/AppSettings.swift +++ b/ElementX/Sources/Application/Settings/AppSettings.swift @@ -16,6 +16,7 @@ import SwiftUI /// Common settings between app and NSE protocol CommonSettingsProtocol: AnyObject { var lastNotificationBootTime: TimeInterval? { get set } + var notificationSoundName: RemotePreference { get } var logLevel: LogLevel { get } var traceLogPacks: Set { get } @@ -298,6 +299,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.lastNotificationBootTime, storageType: .userDefaults(store)) var lastNotificationBootTime: TimeInterval? + /// The name of sound played when delivering noisy notifications. + var notificationSoundName: RemotePreference = .init(.init("message.caf")) + // MARK: - Logging @UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: LogLevel.info, storageType: .userDefaults(store)) diff --git a/Enterprise b/Enterprise index 8dc7d75b8..0b9ba971f 160000 --- a/Enterprise +++ b/Enterprise @@ -1 +1 @@ -Subproject commit 8dc7d75b883dbd12dc0ba978c6719f4d1032534e +Subproject commit 0b9ba971fb764b0b04eaf7bc45ad75af0c367007 diff --git a/NSE/Sources/NotificationContentBuilder.swift b/NSE/Sources/NotificationContentBuilder.swift index 9e3f1de77..b139172ba 100644 --- a/NSE/Sources/NotificationContentBuilder.swift +++ b/NSE/Sources/NotificationContentBuilder.swift @@ -15,6 +15,7 @@ import Version struct NotificationContentBuilder { let messageEventStringBuilder: RoomMessageEventStringBuilder + let notificationSoundName: UNNotificationSoundName let userSession: NSEUserSessionProtocol /// Process the given notification item proxy @@ -48,7 +49,7 @@ struct NotificationContentBuilder { notificationContent.threadIdentifier = threadIdentifier.replacingOccurrences(of: "@", with: "") MXLog.info("isNoisy: \(notificationItem.isNoisy)") - notificationContent.sound = notificationItem.isNoisy ? UNNotificationSound(named: UNNotificationSoundName(rawValue: "message.caf")) : nil + notificationContent.sound = notificationItem.isNoisy ? .init(named: notificationSoundName) : nil switch notificationItem.event { case .none: diff --git a/NSE/Sources/NotificationHandler.swift b/NSE/Sources/NotificationHandler.swift index a8a97785f..cad2c91cf 100644 --- a/NSE/Sources/NotificationHandler.swift +++ b/NSE/Sources/NotificationHandler.swift @@ -37,6 +37,7 @@ class NotificationHandler { destination: .notification) notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: eventStringBuilder, + notificationSoundName: settings.notificationSoundName.publisher.value, userSession: userSession) } diff --git a/NSE/Sources/NotificationServiceExtension.swift b/NSE/Sources/NotificationServiceExtension.swift index 5ab7f6ea4..1d8f001b8 100644 --- a/NSE/Sources/NotificationServiceExtension.swift +++ b/NSE/Sources/NotificationServiceExtension.swift @@ -231,7 +231,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension { let content = UNMutableNotificationContent() content.body = L10n.notificationReceivedWhileOfflineIos content.badge = originalRequest.content.unreadCount as NSNumber? - content.sound = .init(named: .init("message.caf")) + content.sound = .init(named: settings.notificationSoundName.publisher.value) let request = UNNotificationRequest(identifier: Self.receivedWhileOfflineNotificationID, content: content, trigger: nil) UNUserNotificationCenter.current().add(request) diff --git a/UnitTests/Sources/NotificationContentBuilderTests.swift b/UnitTests/Sources/NotificationContentBuilderTests.swift index 7bac15a53..02ccdd26b 100644 --- a/UnitTests/Sources/NotificationContentBuilderTests.swift +++ b/UnitTests/Sources/NotificationContentBuilderTests.swift @@ -21,6 +21,7 @@ final class NotificationContentBuilderTests: XCTestCase { destination: .notification) mediaProvider = MediaProviderMock(configuration: .init()) notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: stringBuilder, + notificationSoundName: UNNotificationSoundName("message.caf"), userSession: NSEUserSessionMock(.init())) }