Przeglądaj źródła

Cleanup: drop dead allowNotify / removeGlucoseNotifications

* Router.allowNotify + both callers removed (gated nothing after
  glucoseNotificationsOption was deleted)
* BaseUserNotificationsManager.removeGlucoseNotifications removed
  (last caller turned into a one-line delegation)
* SnoozeStateModel.applySnooze drops a redundant direct write;
  BaseTrioAlertManager.applySnooze is the single writer
Deniz Cengiz 4 tygodni temu
rodzic
commit
3355cb62db

+ 0 - 1
Trio/Sources/Modules/Main/MainStateModel.swift

@@ -219,7 +219,6 @@ extension Main {
                 .receive(on: DispatchQueue.main)
                 .sink { message in
                     guard !self.isApnPumpConfigAction(message) else { return }
-                    guard self.router.allowNotify(message, self.settingsManager.settings) else { return }
                     self.showAlertMessage(message)
                 }
                 .store(in: &lifetime)

+ 4 - 2
Trio/Sources/Modules/Snooze/SnoozeStateModel.swift

@@ -28,8 +28,10 @@ extension Snooze {
         }
 
         @MainActor func applySnooze(_ duration: TimeInterval) async {
-            // Allow any duration chosen in the Snooze UI, while keeping validation for quick actions elsewhere.
-            snoozeUntilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast
+            // Canonical path: notificationsManager.applySnooze → BaseTrioAlertManager
+            // writes the persisted date, mutes AlertMuter, clears pending UNs, and
+            // broadcasts SnoozeObserver. `snoozeDidChange` below then updates the
+            // @Persisted value here for SwiftUI observation.
             alarm = glucoseStorage.alarm
             await notificationsManager.applySnooze(for: duration)
         }

+ 0 - 12
Trio/Sources/Router/Router.swift

@@ -33,7 +33,6 @@ protocol Router {
     var mainSecondaryModalView: CurrentValueSubject<AnyView?, Never> { get }
     var alertMessage: PassthroughSubject<MessageContent, Never> { get }
     func view(for screen: Screen) -> AnyView
-    func allowNotify(_ message: MessageContent, _ settings: TrioSettings) -> Bool
 }
 
 final class BaseRouter: Router {
@@ -49,15 +48,4 @@ final class BaseRouter: Router {
     func view(for screen: Screen) -> AnyView {
         screen.view(resolver: resolver).asAny()
     }
-
-    func allowNotify(_ message: MessageContent, _: TrioSettings) -> Bool {
-        if message.type == .error { return true }
-        if message.subtype == .glucose {
-            // Glucose alarms are owned by `GlucoseAlertCoordinator` and routed
-            // through `TrioAlertManager`. Generic glucose-warning messages on
-            // the legacy bus no longer surface notifications.
-            return false
-        }
-        return true
-    }
 }

+ 0 - 11
Trio/Sources/Services/UserNotifications/UserNotificationsManager.swift

@@ -261,7 +261,6 @@ final class BaseUserNotificationsManager: NSObject, UserNotificationsManager, In
             router.alertMessage.send(messageCont)
             return
         }
-        guard router.allowNotify(messageCont, settingsManager.settings) else { return }
 
         let request = UNNotificationRequest(identifier: alertIdentifier, content: content, trigger: trigger)
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
@@ -326,16 +325,6 @@ extension BaseUserNotificationsManager: alertMessageNotificationObserver {
     }
 }
 
-extension BaseUserNotificationsManager {
-    /// Removes all glucose notifications (delivered and pending).
-    /// Must be called from the main thread. Safe to call from @MainActor contexts.
-    @MainActor private func removeGlucoseNotifications() {
-        let identifier = Identifier.glucoseNotification.rawValue
-        notificationCenter.removeDeliveredNotifications(withIdentifiers: [identifier])
-        notificationCenter.removePendingNotificationRequests(withIdentifiers: [identifier])
-    }
-}
-
 extension BaseUserNotificationsManager: DeterminationObserver {
     func determinationDidUpdate(_ determination: Determination) {
         guard let carndRequired = determination.carbsReq else { return }