summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@codic.se>2025-01-28 12:31:23 +0100
committerBug Magnet <marco.nikic@mullvad.net>2025-01-29 10:24:05 +0100
commitd1bc47eaaab0082055dac35b670983294cfeed99 (patch)
tree633525ee610434c31902a984dd92d9ce98da1fea
parentebb9f989f89dda6921383173661b64d0807a686e (diff)
downloadmullvadvpn-d1bc47eaaab0082055dac35b670983294cfeed99.tar.xz
mullvadvpn-d1bc47eaaab0082055dac35b670983294cfeed99.zip
Add priority for notifications
-rw-r--r--ios/MullvadVPN/Notifications/Notification Providers/AccountExpiryInAppNotificationProvider.swift4
-rw-r--r--ios/MullvadVPN/Notifications/Notification Providers/AccountExpirySystemNotificationProvider.swift4
-rw-r--r--ios/MullvadVPN/Notifications/Notification Providers/LatestChangesNotificationProvider.swift4
-rw-r--r--ios/MullvadVPN/Notifications/Notification Providers/NewDeviceNotificationProvider.swift4
-rw-r--r--ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift4
-rw-r--r--ios/MullvadVPN/Notifications/NotificationManager.swift2
-rw-r--r--ios/MullvadVPN/Notifications/NotificationProvider.swift7
-rw-r--r--ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift10
-rw-r--r--ios/MullvadVPN/Notifications/NotificationProviderProtocol.swift4
9 files changed, 42 insertions, 1 deletions
diff --git a/ios/MullvadVPN/Notifications/Notification Providers/AccountExpiryInAppNotificationProvider.swift b/ios/MullvadVPN/Notifications/Notification Providers/AccountExpiryInAppNotificationProvider.swift
index cbe95c1ce6..b0084bee54 100644
--- a/ios/MullvadVPN/Notifications/Notification Providers/AccountExpiryInAppNotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/Notification Providers/AccountExpiryInAppNotificationProvider.swift
@@ -39,6 +39,10 @@ final class AccountExpiryInAppNotificationProvider: NotificationProvider, InAppN
.accountExpiryInAppNotification
}
+ override var priority: NotificationPriority {
+ .high
+ }
+
// MARK: - InAppNotificationProvider
var notificationDescriptor: InAppNotificationDescriptor? {
diff --git a/ios/MullvadVPN/Notifications/Notification Providers/AccountExpirySystemNotificationProvider.swift b/ios/MullvadVPN/Notifications/Notification Providers/AccountExpirySystemNotificationProvider.swift
index e0e69f747d..a8335a510a 100644
--- a/ios/MullvadVPN/Notifications/Notification Providers/AccountExpirySystemNotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/Notification Providers/AccountExpirySystemNotificationProvider.swift
@@ -45,6 +45,10 @@ final class AccountExpirySystemNotificationProvider: NotificationProvider, Syste
.accountExpirySystemNotification
}
+ override var priority: NotificationPriority {
+ .high
+ }
+
// MARK: - SystemNotificationProvider
var notificationRequest: UNNotificationRequest? {
diff --git a/ios/MullvadVPN/Notifications/Notification Providers/LatestChangesNotificationProvider.swift b/ios/MullvadVPN/Notifications/Notification Providers/LatestChangesNotificationProvider.swift
index 2e72f45545..42e4cac792 100644
--- a/ios/MullvadVPN/Notifications/Notification Providers/LatestChangesNotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/Notification Providers/LatestChangesNotificationProvider.swift
@@ -27,6 +27,10 @@ class LatestChangesNotificationProvider: NotificationProvider, InAppNotification
.latestChangesInAppNotificationProvider
}
+ override var priority: NotificationPriority {
+ .low
+ }
+
var notificationDescriptor: InAppNotificationDescriptor? {
defer {
// Always update the last seen version
diff --git a/ios/MullvadVPN/Notifications/Notification Providers/NewDeviceNotificationProvider.swift b/ios/MullvadVPN/Notifications/Notification Providers/NewDeviceNotificationProvider.swift
index 66b76f9116..4b013c02d1 100644
--- a/ios/MullvadVPN/Notifications/Notification Providers/NewDeviceNotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/Notification Providers/NewDeviceNotificationProvider.swift
@@ -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
diff --git a/ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift b/ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift
index 8a0a3b88ce..b46dc8a202 100644
--- a/ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/Notification Providers/TunnelStatusNotificationProvider.swift
@@ -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)
diff --git a/ios/MullvadVPN/Notifications/NotificationManager.swift b/ios/MullvadVPN/Notifications/NotificationManager.swift
index 378a9bdc1b..924130c93e 100644
--- a/ios/MullvadVPN/Notifications/NotificationManager.swift
+++ b/ios/MullvadVPN/Notifications/NotificationManager.swift
@@ -30,7 +30,7 @@ final class NotificationManager: NotificationProviderDelegate {
newNotificationProvider.delegate = self
}
- _notificationProviders = newNotificationProviders
+ _notificationProviders = newNotificationProviders.sorted { $0.priority > $1.priority }
}
}
diff --git a/ios/MullvadVPN/Notifications/NotificationProvider.swift b/ios/MullvadVPN/Notifications/NotificationProvider.swift
index 8e82313010..57fff1916d 100644
--- a/ios/MullvadVPN/Notifications/NotificationProvider.swift
+++ b/ios/MullvadVPN/Notifications/NotificationProvider.swift
@@ -30,6 +30,13 @@ class NotificationProvider: NotificationProviderProtocol, @unchecked Sendable {
}
/**
+ Default implementation for the priority property, setting it to `.low`.
+ */
+ var priority: NotificationPriority {
+ .low
+ }
+
+ /**
Send action to notification manager delegate.
Usually in response to user interacting with notification banner, i.e by tapping a button. Use different action
diff --git a/ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift b/ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift
index 155d0f7bdb..a01c46055a 100644
--- a/ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift
+++ b/ios/MullvadVPN/Notifications/NotificationProviderIdentifier.swift
@@ -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"
diff --git a/ios/MullvadVPN/Notifications/NotificationProviderProtocol.swift b/ios/MullvadVPN/Notifications/NotificationProviderProtocol.swift
index e4361578c9..1e21bb0a14 100644
--- a/ios/MullvadVPN/Notifications/NotificationProviderProtocol.swift
+++ b/ios/MullvadVPN/Notifications/NotificationProviderProtocol.swift
@@ -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()
}