mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Log whether a notification is expected to make a noise. (#3782)
* Log whether a notification is expected to make a noise. * Also log the system notification sound setting too.
This commit is contained in:
parent
8680d8437b
commit
f6a1d38972
@ -17099,6 +17099,70 @@ class UserNotificationCenterMock: UserNotificationCenterProtocol, @unchecked Sen
|
||||
return authorizationStatusReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - notificationSettings
|
||||
|
||||
var notificationSettingsUnderlyingCallsCount = 0
|
||||
var notificationSettingsCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return notificationSettingsUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = notificationSettingsUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
notificationSettingsUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
notificationSettingsUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var notificationSettingsCalled: Bool {
|
||||
return notificationSettingsCallsCount > 0
|
||||
}
|
||||
|
||||
var notificationSettingsUnderlyingReturnValue: UNNotificationSettings!
|
||||
var notificationSettingsReturnValue: UNNotificationSettings! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return notificationSettingsUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: UNNotificationSettings? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = notificationSettingsUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
notificationSettingsUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
notificationSettingsUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var notificationSettingsClosure: (() async -> UNNotificationSettings)?
|
||||
|
||||
func notificationSettings() async -> UNNotificationSettings {
|
||||
notificationSettingsCallsCount += 1
|
||||
if let notificationSettingsClosure = notificationSettingsClosure {
|
||||
return await notificationSettingsClosure()
|
||||
} else {
|
||||
return notificationSettingsReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
class UserSessionMock: UserSessionProtocol, @unchecked Sendable {
|
||||
var clientProxy: ClientProxyProtocol {
|
||||
|
@ -94,6 +94,9 @@ final class NotificationManager: NSObject, NotificationManagerProtocol {
|
||||
self?.delegate?.registerForRemoteNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
let settings = await notificationCenter.notificationSettings()
|
||||
MXLog.info("Notification sound enabled: \(settings.soundSetting == .enabled)")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ protocol UserNotificationCenterProtocol: AnyObject {
|
||||
func removeDeliveredNotifications(withIdentifiers identifiers: [String])
|
||||
func setNotificationCategories(_ categories: Set<UNNotificationCategory>)
|
||||
func authorizationStatus() async -> UNAuthorizationStatus
|
||||
func notificationSettings() async -> UNNotificationSettings
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
|
@ -53,16 +53,20 @@ struct NotificationContentBuilder {
|
||||
|
||||
func baseMutableContent(for notificationItem: NotificationItemProxyProtocol) -> UNMutableNotificationContent {
|
||||
let notification = UNMutableNotificationContent()
|
||||
|
||||
notification.receiverID = notificationItem.receiverID
|
||||
notification.roomID = notificationItem.roomID
|
||||
notification.eventID = switch notificationItem.event {
|
||||
case .timeline(let event): event.eventId()
|
||||
case .invite, .none: nil
|
||||
}
|
||||
notification.sound = notificationItem.isNoisy ? UNNotificationSound(named: UNNotificationSoundName(rawValue: "message.caf")) : nil
|
||||
// So that the UI groups notification that are received for the same room but also for the same user
|
||||
// Removing the @ fixes an iOS bug where the notification crashes if the mute button is tapped
|
||||
notification.threadIdentifier = "\(notificationItem.receiverID)\(notificationItem.roomID)".replacingOccurrences(of: "@", with: "")
|
||||
|
||||
MXLog.info("isNoisy: \(notificationItem.isNoisy)")
|
||||
notification.sound = notificationItem.isNoisy ? UNNotificationSound(named: UNNotificationSoundName(rawValue: "message.caf")) : nil
|
||||
|
||||
return notification
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ final class NotificationManagerTests: XCTestCase {
|
||||
notificationCenter = UserNotificationCenterMock()
|
||||
notificationCenter.requestAuthorizationOptionsReturnValue = true
|
||||
notificationCenter.authorizationStatusReturnValue = .authorized
|
||||
notificationCenter.notificationSettingsClosure = { await UNUserNotificationCenter.current().notificationSettings() }
|
||||
|
||||
notificationManager = NotificationManager(notificationCenter: notificationCenter, appSettings: appSettings)
|
||||
notificationManager.start()
|
||||
|
Loading…
x
Reference in New Issue
Block a user