diff --git a/Pulse/GitHubAPI.swift b/Pulse/GitHubAPI.swift index e4f520d..a962396 100644 --- a/Pulse/GitHubAPI.swift +++ b/Pulse/GitHubAPI.swift @@ -50,8 +50,11 @@ struct PullRequest: Identifiable { typealias PullRequests = [PullRequest] func - (left: PullRequests, right: PullRequests) -> PullRequests { - let rightIDs = right.map { $0.id } - return left.filter { !rightIDs.contains($0.id) } + let rightTups = right.map { ($0.id, $0.reviewResult, $0.checkResult) } + return left.filter { + let tup = ($0.id, $0.reviewResult, $0.checkResult) + return !rightTups.contains { $0 == tup } + } } actor GitHubAPI { diff --git a/Pulse/Notification.swift b/Pulse/Notification.swift index 64592c1..0321c18 100644 --- a/Pulse/Notification.swift +++ b/Pulse/Notification.swift @@ -1,6 +1,8 @@ import UserNotifications enum Notification { + private static let bundleIdentifier = Bundle.main.bundleIdentifier! + static func notify(id: String, title: String, body: String, url: String) async { let userNotificationCenter = UNUserNotificationCenter.current() @@ -10,7 +12,14 @@ enum Notification { content.userInfo = ["url": url] content.sound = UNNotificationSound.default - let req = UNNotificationRequest(identifier: "\(Bundle.main.bundleIdentifier!).\(id)", content: content, trigger: nil) + let req = UNNotificationRequest(identifier: "\(bundleIdentifier).\(id)", content: content, trigger: nil) try? await userNotificationCenter.add(req) } + + static func remove(ids: [String]) { + let userNotificationCenter = UNUserNotificationCenter.current() + let idsWithBundleId = ids.map { "\(bundleIdentifier).\($0)" } + userNotificationCenter.removeDeliveredNotifications( + withIdentifiers: idsWithBundleId) + } } diff --git a/Pulse/PullRequestModel.swift b/Pulse/PullRequestModel.swift index 6973f7a..22495c5 100644 --- a/Pulse/PullRequestModel.swift +++ b/Pulse/PullRequestModel.swift @@ -49,6 +49,11 @@ class PullRequestModel: ObservableObject { if !newSettled.isEmpty { notify(newSettled) } + + if !pending.isEmpty { + let ids = pending.map { $0.id } + Notification.remove(ids: ids) + } } catch let githubError as GitHubError { error = githubError status = .error