From a2a4616a48f82500965b839aeff03f0468c15679 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 4 Oct 2019 11:20:57 -0500 Subject: [PATCH] Remove article notification when an article is read --- Shared/UserNotifications/UserNotificationManager.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Shared/UserNotifications/UserNotificationManager.swift b/Shared/UserNotifications/UserNotificationManager.swift index 5857b1abe..ce1838541 100644 --- a/Shared/UserNotifications/UserNotificationManager.swift +++ b/Shared/UserNotifications/UserNotificationManager.swift @@ -16,6 +16,7 @@ final class UserNotificationManager: NSObject { override init() { super.init() NotificationCenter.default.addObserver(self, selector: #selector(accountDidDownloadArticles(_:)), name: .AccountDidDownloadArticles, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) } @objc func accountDidDownloadArticles(_ note: Notification) { @@ -30,6 +31,14 @@ final class UserNotificationManager: NSObject { } } + @objc func statusesDidChange(_ note: Notification) { + guard let articles = note.userInfo?[Account.UserInfoKey.articles] as? Set
else { + return + } + let identifiers = articles.filter({ $0.status.read }).map { "articleID:\($0.articleID)" } + UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers) + } + } private extension UserNotificationManager {