diff options
Diffstat (limited to 'DomainDig/LocalNotificationService.swift')
| -rw-r--r-- | DomainDig/LocalNotificationService.swift | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/DomainDig/LocalNotificationService.swift b/DomainDig/LocalNotificationService.swift index 7b43d67..93beca5 100644 --- a/DomainDig/LocalNotificationService.swift +++ b/DomainDig/LocalNotificationService.swift @@ -78,6 +78,35 @@ final class LocalNotificationService { ) } + func notifyMonitoringSummary( + domain: String, + alerts: [MonitoringPendingAlert] + ) async { + let summary = alerts + .sorted { $0.detectedAt < $1.detectedAt } + .prefix(2) + .map(\.message) + .joined(separator: " • ") + let body: String + if alerts.count <= 1 { + body = alerts.first?.message ?? "Monitoring change detected" + } else if summary.isEmpty { + body = "\(alerts.count) monitoring changes detected" + } else { + body = "\(alerts.count) monitoring changes: \(summary)" + } + + let severity = alerts.map(\.severity).max() ?? .info + let interruptionLevel: UNNotificationInterruptionLevel = severity == .critical ? .timeSensitive : .active + + await schedule( + identifier: "monitoring-summary-\(domain)-\(UUID().uuidString)", + title: domain, + body: body, + interruptionLevel: interruptionLevel + ) + } + func notifySweepComplete(summary: BatchSweepSummary) async { let body = "\(summary.changedDomains) changed, \(summary.warningDomains) warnings, \(summary.unchangedDomains) unchanged" await schedule( |
