Make articles older than a specified period unable to be marked as unread. Issue #1407

This commit is contained in:
Maurice Parker 2020-02-29 10:30:35 -08:00
parent 380614afc3
commit c17ce1ceaa
4 changed files with 22 additions and 16 deletions

View File

@ -159,7 +159,7 @@ private extension TimelineViewController {
if articles.anyArticleIsUnread() { if articles.anyArticleIsUnread() {
menu.addItem(markReadMenuItem(articles)) menu.addItem(markReadMenuItem(articles))
} }
if articles.anyArticleIsRead() { if articles.anyArticleIsReadAndCanMarkUnread() {
menu.addItem(markUnreadMenuItem(articles)) menu.addItem(markUnreadMenuItem(articles))
} }
if articles.anyArticleIsUnstarred() { if articles.anyArticleIsUnstarred() {

View File

@ -367,7 +367,17 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
} }
func markReadCommandStatus() -> MarkCommandValidationStatus { func markReadCommandStatus() -> MarkCommandValidationStatus {
return MarkCommandValidationStatus.statusFor(selectedArticles) { $0.anyArticleIsUnread() } let articles = selectedArticles
if articles.anyArticleIsUnread() {
return .canMark
}
if articles.anyArticleIsReadAndCanMarkUnread() {
return .canUnmark
}
return .canDoNothing
} }
func markOlderArticlesRead() { func markOlderArticlesRead() {

View File

@ -23,7 +23,7 @@ final class MarkStatusCommand: UndoableCommand {
init?(initialArticles: [Article], statusKey: ArticleStatus.Key, flag: Bool, undoManager: UndoManager) { init?(initialArticles: [Article], statusKey: ArticleStatus.Key, flag: Bool, undoManager: UndoManager) {
// Filter out articles that already have the desired status. // Filter out articles that already have the desired status or can't be marked.
let articlesToMark = MarkStatusCommand.filteredArticles(initialArticles, statusKey, flag) let articlesToMark = MarkStatusCommand.filteredArticles(initialArticles, statusKey, flag)
if articlesToMark.isEmpty { if articlesToMark.isEmpty {
return nil return nil
@ -88,6 +88,12 @@ private extension MarkStatusCommand {
static func filteredArticles(_ articles: [Article], _ statusKey: ArticleStatus.Key, _ flag: Bool) -> [Article] { static func filteredArticles(_ articles: [Article], _ statusKey: ArticleStatus.Key, _ flag: Bool) -> [Article] {
return articles.filter{ $0.status.boolStatus(forKey: statusKey) != flag } return articles.filter{ article in
guard article.status.boolStatus(forKey: statusKey) != flag else { return false }
guard statusKey == .read else { return true }
guard !article.status.read || article.isAvailableToMarkUnread else { return false }
return true
}
} }
} }

View File

@ -14,7 +14,6 @@ typealias ArticleArray = [Article]
extension Array where Element == Article { extension Array where Element == Article {
func articleAtRow(_ row: Int) -> Article? { func articleAtRow(_ row: Int) -> Article? {
if row < 0 || row == NSNotFound || row > count - 1 { if row < 0 || row == NSNotFound || row > count - 1 {
return nil return nil
} }
@ -22,7 +21,6 @@ extension Array where Element == Article {
} }
func rowOfNextUnreadArticle(_ selectedRow: Int) -> Int? { func rowOfNextUnreadArticle(_ selectedRow: Int) -> Int? {
if isEmpty { if isEmpty {
return nil return nil
} }
@ -44,7 +42,6 @@ extension Array where Element == Article {
} }
func articlesForIndexes(_ indexes: IndexSet) -> Set<Article> { func articlesForIndexes(_ indexes: IndexSet) -> Set<Article> {
return Set(indexes.compactMap{ (oneIndex) -> Article? in return Set(indexes.compactMap{ (oneIndex) -> Article? in
return articleAtRow(oneIndex) return articleAtRow(oneIndex)
}) })
@ -55,12 +52,10 @@ extension Array where Element == Article {
} }
func canMarkAllAsRead() -> Bool { func canMarkAllAsRead() -> Bool {
return anyArticleIsUnread() return anyArticleIsUnread()
} }
func anyArticlePassesTest(_ test: ((Article) -> Bool)) -> Bool { func anyArticlePassesTest(_ test: ((Article) -> Bool)) -> Bool {
for article in self { for article in self {
if test(article) { if test(article) {
return true return true
@ -69,28 +64,23 @@ extension Array where Element == Article {
return false return false
} }
func anyArticleIsRead() -> Bool { func anyArticleIsReadAndCanMarkUnread() -> Bool {
return anyArticlePassesTest { $0.status.read && $0.isAvailableToMarkUnread }
return anyArticlePassesTest { $0.status.read }
} }
func anyArticleIsUnread() -> Bool { func anyArticleIsUnread() -> Bool {
return anyArticlePassesTest { !$0.status.read } return anyArticlePassesTest { !$0.status.read }
} }
func anyArticleIsStarred() -> Bool { func anyArticleIsStarred() -> Bool {
return anyArticlePassesTest { $0.status.starred } return anyArticlePassesTest { $0.status.starred }
} }
func anyArticleIsUnstarred() -> Bool { func anyArticleIsUnstarred() -> Bool {
return anyArticlePassesTest { !$0.status.starred } return anyArticlePassesTest { !$0.status.starred }
} }
func unreadArticles() -> [Article]? { func unreadArticles() -> [Article]? {
let articles = self.filter{ !$0.status.read } let articles = self.filter{ !$0.status.read }
return articles.isEmpty ? nil : articles return articles.isEmpty ? nil : articles
} }