Implement mark all as read in feed context menu for timeline

This commit is contained in:
Maurice Parker 2020-07-17 20:29:53 -05:00
parent 644e9da1c0
commit 2a4a13ed13
2 changed files with 25 additions and 0 deletions

View File

@ -81,6 +81,18 @@ struct TimelineContextMenu: View {
}
}
if let feed = timelineItem.article.webFeed, timelineModel.canMarkAllAsReadInFeed(feed) {
Divider()
Button {
timelineModel.markAllAsReadInFeed(feed)
} label: {
Text("Mark All as Read in “\(feed.nameForDisplay)")
#if os(iOS)
AppAssets.markAllAsReadImage
#endif
}
}
if timelineModel.canOpenIndicatedArticleInBrowser(timelineItem.article) {
Divider()
Button {

View File

@ -189,6 +189,19 @@ class TimelineModel: ObservableObject, UndoableCommandRunner {
markArticlesWithUndo(articlesToMark, statusKey: .read, flag: true)
}
func canMarkAllAsReadInFeed(_ feed: Feed) -> Bool {
guard let articlesSet = try? feed.fetchArticles() else {
return false
}
return Array(articlesSet).canMarkAllAsRead()
}
func markAllAsReadInFeed(_ feed: Feed) {
guard let articlesSet = try? feed.fetchArticles() else { return }
let articlesToMark = Array(articlesSet)
markArticlesWithUndo(articlesToMark, statusKey: .read, flag: true)
}
func toggleStarredStatusForSelectedArticles() {
guard !selectedArticles.isEmpty else {
return