mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Define the notification sound name in AppSettings. (#5106)
This commit is contained in:
@@ -16,6 +16,7 @@ import SwiftUI
|
|||||||
/// Common settings between app and NSE
|
/// Common settings between app and NSE
|
||||||
protocol CommonSettingsProtocol: AnyObject {
|
protocol CommonSettingsProtocol: AnyObject {
|
||||||
var lastNotificationBootTime: TimeInterval? { get set }
|
var lastNotificationBootTime: TimeInterval? { get set }
|
||||||
|
var notificationSoundName: RemotePreference<UNNotificationSoundName> { get }
|
||||||
|
|
||||||
var logLevel: LogLevel { get }
|
var logLevel: LogLevel { get }
|
||||||
var traceLogPacks: Set<TraceLogPack> { get }
|
var traceLogPacks: Set<TraceLogPack> { get }
|
||||||
@@ -298,6 +299,9 @@ final class AppSettings {
|
|||||||
@UserPreference(key: UserDefaultsKeys.lastNotificationBootTime, storageType: .userDefaults(store))
|
@UserPreference(key: UserDefaultsKeys.lastNotificationBootTime, storageType: .userDefaults(store))
|
||||||
var lastNotificationBootTime: TimeInterval?
|
var lastNotificationBootTime: TimeInterval?
|
||||||
|
|
||||||
|
/// The name of sound played when delivering noisy notifications.
|
||||||
|
var notificationSoundName: RemotePreference<UNNotificationSoundName> = .init(.init("message.caf"))
|
||||||
|
|
||||||
// MARK: - Logging
|
// MARK: - Logging
|
||||||
|
|
||||||
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: LogLevel.info, storageType: .userDefaults(store))
|
@UserPreference(key: UserDefaultsKeys.logLevel, defaultValue: LogLevel.info, storageType: .userDefaults(store))
|
||||||
|
|||||||
+1
-1
Submodule Enterprise updated: 8dc7d75b88...0b9ba971fb
@@ -15,6 +15,7 @@ import Version
|
|||||||
|
|
||||||
struct NotificationContentBuilder {
|
struct NotificationContentBuilder {
|
||||||
let messageEventStringBuilder: RoomMessageEventStringBuilder
|
let messageEventStringBuilder: RoomMessageEventStringBuilder
|
||||||
|
let notificationSoundName: UNNotificationSoundName
|
||||||
let userSession: NSEUserSessionProtocol
|
let userSession: NSEUserSessionProtocol
|
||||||
|
|
||||||
/// Process the given notification item proxy
|
/// Process the given notification item proxy
|
||||||
@@ -48,7 +49,7 @@ struct NotificationContentBuilder {
|
|||||||
notificationContent.threadIdentifier = threadIdentifier.replacingOccurrences(of: "@", with: "")
|
notificationContent.threadIdentifier = threadIdentifier.replacingOccurrences(of: "@", with: "")
|
||||||
|
|
||||||
MXLog.info("isNoisy: \(notificationItem.isNoisy)")
|
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 {
|
switch notificationItem.event {
|
||||||
case .none:
|
case .none:
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class NotificationHandler {
|
|||||||
destination: .notification)
|
destination: .notification)
|
||||||
|
|
||||||
notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: eventStringBuilder,
|
notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: eventStringBuilder,
|
||||||
|
notificationSoundName: settings.notificationSoundName.publisher.value,
|
||||||
userSession: userSession)
|
userSession: userSession)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ class NotificationServiceExtension: UNNotificationServiceExtension {
|
|||||||
let content = UNMutableNotificationContent()
|
let content = UNMutableNotificationContent()
|
||||||
content.body = L10n.notificationReceivedWhileOfflineIos
|
content.body = L10n.notificationReceivedWhileOfflineIos
|
||||||
content.badge = originalRequest.content.unreadCount as NSNumber?
|
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)
|
let request = UNNotificationRequest(identifier: Self.receivedWhileOfflineNotificationID, content: content, trigger: nil)
|
||||||
UNUserNotificationCenter.current().add(request)
|
UNUserNotificationCenter.current().add(request)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ final class NotificationContentBuilderTests: XCTestCase {
|
|||||||
destination: .notification)
|
destination: .notification)
|
||||||
mediaProvider = MediaProviderMock(configuration: .init())
|
mediaProvider = MediaProviderMock(configuration: .init())
|
||||||
notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: stringBuilder,
|
notificationContentBuilder = NotificationContentBuilder(messageEventStringBuilder: stringBuilder,
|
||||||
|
notificationSoundName: UNNotificationSoundName("message.caf"),
|
||||||
userSession: NSEUserSessionMock(.init()))
|
userSession: NSEUserSessionMock(.init()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user