Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority for notifications #7530

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading