Enhance StatusDidChange message to pass status and flag when not passing full articles. Fixes #3481
This commit is contained in:
parent
a629560f65
commit
772948307e
|
@ -72,6 +72,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
public static let statuses = "statuses" // StatusesDidChange
|
||||
public static let articles = "articles" // StatusesDidChange
|
||||
public static let articleIDs = "articleIDs" // StatusesDidChange
|
||||
public static let statusKey = "statusKey" // StatusesDidChange
|
||||
public static let statusFlag = "statusFlag" // StatusesDidChange
|
||||
public static let webFeeds = "webFeeds" // AccountDidDownloadArticles, StatusesDidChange
|
||||
public static let syncErrors = "syncErrors" // AccountsDidFailToSyncWithErrors
|
||||
}
|
||||
|
@ -845,7 +847,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
database.markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag) { result in
|
||||
switch result {
|
||||
case .success(let newArticleStatusIDs):
|
||||
self.noteStatusesForArticleIDsDidChange(articleIDs)
|
||||
self.noteStatusesForArticleIDsDidChange(articleIDs: articleIDs, statusKey: statusKey, flag: flag)
|
||||
completion?(.success(newArticleStatusIDs))
|
||||
case .failure(let databaseError):
|
||||
completion?(.failure(databaseError))
|
||||
|
@ -1268,6 +1270,11 @@ private extension Account {
|
|||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.statuses: statuses, UserInfoKey.articles: articles, UserInfoKey.articleIDs: articleIDs, UserInfoKey.webFeeds: feeds])
|
||||
}
|
||||
|
||||
func noteStatusesForArticleIDsDidChange(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool) {
|
||||
fetchAllUnreadCounts()
|
||||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.articleIDs: articleIDs, UserInfoKey.statusKey: statusKey, UserInfoKey.statusFlag: flag])
|
||||
}
|
||||
|
||||
func noteStatusesForArticleIDsDidChange(_ articleIDs: Set<String>) {
|
||||
fetchAllUnreadCounts()
|
||||
NotificationCenter.default.post(name: .StatusesDidChange, object: self, userInfo: [UserInfoKey.articleIDs: articleIDs])
|
||||
|
|
|
@ -33,11 +33,20 @@ final class UserNotificationManager: NSObject {
|
|||
}
|
||||
|
||||
@objc func statusesDidChange(_ note: Notification) {
|
||||
guard let statuses = note.userInfo?[Account.UserInfoKey.statuses] as? Set<ArticleStatus>, !statuses.isEmpty else {
|
||||
if let statuses = note.userInfo?[Account.UserInfoKey.statuses] as? Set<ArticleStatus>, !statuses.isEmpty {
|
||||
let identifiers = statuses.filter({ $0.read }).map { "articleID:\($0.articleID)" }
|
||||
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
|
||||
return
|
||||
}
|
||||
let identifiers = statuses.filter({ $0.read }).map { "articleID:\($0.articleID)" }
|
||||
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
|
||||
|
||||
if let articleIDs = note.userInfo?[Account.UserInfoKey.articleIDs] as? Set<String>,
|
||||
let statusKey = note.userInfo?[Account.UserInfoKey.statusKey] as? ArticleStatus.Key,
|
||||
let flag = note.userInfo?[Account.UserInfoKey.statusFlag] as? Bool,
|
||||
statusKey == .read,
|
||||
flag == true {
|
||||
let identifiers = articleIDs.map { "articleID:\($0)" }
|
||||
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: identifiers)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue