mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Only register for notifications when the setting is enabled. (#2819)
This commit is contained in:
@@ -98,7 +98,7 @@ final class NotificationManager: NSObject, NotificationManagerProtocol {
|
|||||||
Task { [weak self] in
|
Task { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
if await notificationCenter.authorizationStatus() == .authorized {
|
if await notificationCenter.authorizationStatus() == .authorized, appSettings.enableNotifications {
|
||||||
await MainActor.run { [weak self] in
|
await MainActor.run { [weak self] in
|
||||||
self?.delegate?.registerForRemoteNotifications()
|
self?.delegate?.registerForRemoteNotifications()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,6 +163,38 @@ final class NotificationManagerTests: XCTestCase {
|
|||||||
await fulfillment(of: [expectation])
|
await fulfillment(of: [expectation])
|
||||||
XCTAssertTrue(authorizationStatusWasGranted)
|
XCTAssertTrue(authorizationStatusWasGranted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func test_whenStartAndAuthorizedAndNotificationDisabled_registerForRemoteNotificationsNotCalled() async throws {
|
||||||
|
appSettings.enableNotifications = false
|
||||||
|
notificationCenter.authorizationStatusReturnValue = .authorized
|
||||||
|
notificationManager.delegate = self
|
||||||
|
|
||||||
|
notificationManager.setUserSession(MockUserSession(clientProxy: ClientProxyMock(),
|
||||||
|
mediaProvider: MockMediaProvider(),
|
||||||
|
voiceMessageMediaManager: VoiceMessageMediaManagerMock()))
|
||||||
|
try await Task.sleep(for: .seconds(1))
|
||||||
|
|
||||||
|
XCTAssertFalse(authorizationStatusWasGranted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_whenStartAndAuthorized_registerForRemoteNotificationsCalled() async throws {
|
||||||
|
appSettings.enableNotifications = true
|
||||||
|
notificationCenter.authorizationStatusReturnValue = .authorized
|
||||||
|
notificationManager.delegate = self
|
||||||
|
|
||||||
|
let expectation: XCTestExpectation = expectation(description: "registerForRemoteNotifications delegate function should be called")
|
||||||
|
expectation.assertForOverFulfill = false
|
||||||
|
registerForRemoteNotificationsDelegateCalled = {
|
||||||
|
expectation.fulfill()
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationManager.setUserSession(MockUserSession(clientProxy: ClientProxyMock(),
|
||||||
|
mediaProvider: MockMediaProvider(),
|
||||||
|
voiceMessageMediaManager: VoiceMessageMediaManagerMock()))
|
||||||
|
await fulfillment(of: [expectation])
|
||||||
|
|
||||||
|
XCTAssertTrue(authorizationStatusWasGranted)
|
||||||
|
}
|
||||||
|
|
||||||
func test_whenWillPresentNotificationsDelegateNotSet_CorrectPresentationOptionsReturned() async throws {
|
func test_whenWillPresentNotificationsDelegateNotSet_CorrectPresentationOptionsReturned() async throws {
|
||||||
let archiver = MockCoder(requiringSecureCoding: false)
|
let archiver = MockCoder(requiringSecureCoding: false)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Only register for notifications when the setting is enabled.
|
||||||
Reference in New Issue
Block a user