Skip to content

Commit

Permalink
Add priority for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Jan 28, 2025
1 parent df30121 commit c5a4d45
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ final class AccountExpiryInAppNotificationProvider: NotificationProvider, InAppN
.accountExpiryInAppNotification
}

override var priority: NotificationPriority {
.high
}

// MARK: - InAppNotificationProvider

var notificationDescriptor: InAppNotificationDescriptor? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ final class AccountExpirySystemNotificationProvider: NotificationProvider, Syste
.accountExpirySystemNotification
}

override var priority: NotificationPriority {
.high
}

// MARK: - SystemNotificationProvider

var notificationRequest: UNNotificationRequest? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class LatestChangesNotificationProvider: NotificationProvider, InAppNotification
.latestChangesInAppNotificationProvider
}

override var priority: NotificationPriority {
.low
}

var notificationDescriptor: InAppNotificationDescriptor? {
defer {
// Always update the last seen version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ final class NewDeviceNotificationProvider: NotificationProvider,
.registeredDeviceInAppNotification
}

override var priority: NotificationPriority {
.medium
}

private func addObservers() {
tunnelObserver =
TunnelBlockObserver(didUpdateDeviceState: { [weak self] _, deviceState, previousDeviceState in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ final class TunnelStatusNotificationProvider: NotificationProvider, InAppNotific
.tunnelStatusNotificationProvider
}

override var priority: NotificationPriority {
.critical
}

var notificationDescriptor: InAppNotificationDescriptor? {
if let packetTunnelError {
return notificationDescription(for: packetTunnelError)
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class NotificationManager: NotificationProviderDelegate {
newNotificationProvider.delegate = self
}

_notificationProviders = newNotificationProviders
_notificationProviders = newNotificationProviders.sorted { $0.priority > $1.priority }
}
}

Expand Down
7 changes: 7 additions & 0 deletions ios/MullvadVPN/Notifications/NotificationProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class NotificationProvider: NotificationProviderProtocol, @unchecked Sendable {
.default
}

/**
Default implementation for the priority property, setting it to `.low`.
*/
var priority: NotificationPriority {
.low
}

/**
Send action to notification manager delegate.

Expand Down
10 changes: 10 additions & 0 deletions ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
//

import Foundation
enum NotificationPriority: Int, Comparable {
case low = 1
case medium = 2
case high = 3
case critical = 4

static func < (lhs: NotificationPriority, rhs: NotificationPriority) -> Bool {
return lhs.rawValue < rhs.rawValue
}
}

enum NotificationProviderIdentifier: String {
case accountExpirySystemNotification = "AccountExpiryNotification"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ protocol NotificationProviderProtocol {
/// produced by them.
var identifier: NotificationProviderIdentifier { get }

/// The priority level of the notification, used to determine the order in which notifications
/// should be displayed. Higher priority notifications are displayed first.
var priority: NotificationPriority { get }

/// Tell notification manager to update the associated notification.
func invalidate()
}

0 comments on commit c5a4d45

Please sign in to comment.