Remove article notification when an article is read

This commit is contained in:
Maurice Parker 2019-10-04 11:20:57 -05:00
parent c50ed3e44c
commit a2a4616a48
1 changed files with 9 additions and 0 deletions

View File

@ -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<Article> else {
return
}
let identifiers = articles.filter({ $0.status.read }).map { "articleID:\($0.articleID)" }
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
}
}
private extension UserNotificationManager {