mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Fix article read filter which wasn't persisting correctly.
This commit is contained in:
parent
202ee57697
commit
343f705cd7
@ -58,7 +58,7 @@ struct AppDefaults {
|
||||
|
||||
static var windowState: [AnyHashable : Any]? {
|
||||
get {
|
||||
UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable : Any]
|
||||
return UserDefaults.standard.object(forKey: Key.windowState) as? [AnyHashable : Any]
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: Key.windowState)
|
||||
|
@ -248,11 +248,8 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
// MARK: State Restoration
|
||||
|
||||
func saveState(to state: inout [AnyHashable : Any]) {
|
||||
var readArticlesFilterState = [[AnyHashable: AnyHashable]: Bool]()
|
||||
for key in readFilterEnabledTable.keys {
|
||||
readArticlesFilterState[key.userInfo] = readFilterEnabledTable[key]
|
||||
}
|
||||
state[UserInfoKey.readArticlesFilterState] = readArticlesFilterState
|
||||
state[UserInfoKey.readArticlesFilterStateKeys] = readFilterEnabledTable.keys.compactMap { $0.userInfo }
|
||||
state[UserInfoKey.readArticlesFilterStateValues] = readFilterEnabledTable.values.compactMap( { $0 })
|
||||
|
||||
if selectedArticles.count == 1 {
|
||||
state[UserInfoKey.articlePath] = selectedArticles.first!.pathUserInfo
|
||||
@ -260,25 +257,24 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
func restoreState(from state: [AnyHashable : Any]) {
|
||||
if let readArticlesFilterState = state[UserInfoKey.readArticlesFilterState] as? [[AnyHashable: AnyHashable]: Bool] {
|
||||
for key in readArticlesFilterState.keys {
|
||||
if let feedIdentifier = FeedIdentifier(userInfo: key) {
|
||||
readFilterEnabledTable[feedIdentifier] = readArticlesFilterState[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
guard let articlePathUserInfo = state[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let account = AccountManager.shared.existingAccount(with: accountID),
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
|
||||
guard let readArticlesFilterStateKeys = state[UserInfoKey.readArticlesFilterStateKeys] as? [[AnyHashable: AnyHashable]],
|
||||
let readArticlesFilterStateValues = state[UserInfoKey.readArticlesFilterStateValues] as? [Bool] else {
|
||||
return
|
||||
}
|
||||
|
||||
if isReadFiltered ?? true {
|
||||
for i in 0..<readArticlesFilterStateKeys.count {
|
||||
if let feedIdentifier = FeedIdentifier(userInfo: readArticlesFilterStateKeys[i]) {
|
||||
readFilterEnabledTable[feedIdentifier] = readArticlesFilterStateValues[i]
|
||||
}
|
||||
}
|
||||
|
||||
if let articlePathUserInfo = state[UserInfoKey.articlePath] as? [AnyHashable : Any],
|
||||
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
|
||||
let account = AccountManager.shared.existingAccount(with: accountID),
|
||||
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String {
|
||||
|
||||
exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: articleID)
|
||||
fetchAndReplaceArticlesSync()
|
||||
}
|
||||
|
||||
if let selectedIndex = articles.firstIndex(where: { $0.articleID == articleID }) {
|
||||
tableView.selectRow(selectedIndex)
|
||||
@ -286,6 +282,12 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
focus()
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
fetchAndReplaceArticlesSync()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
@ -19,6 +19,8 @@ struct UserInfoKey {
|
||||
static let containerExpandedWindowState = "containerExpandedWindowState"
|
||||
static let readFeedsFilterState = "readFeedsFilterState"
|
||||
static let readArticlesFilterState = "readArticlesFilterState"
|
||||
static let readArticlesFilterStateKeys = "readArticlesFilterStateKey"
|
||||
static let readArticlesFilterStateValues = "readArticlesFilterStateValue"
|
||||
static let selectedFeedsState = "selectedFeedsState"
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user