mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add Newsletters and Read Later shortcuts
This commit is contained in:
parent
b45120706b
commit
07c6792cde
1 changed files with 21 additions and 3 deletions
|
|
@ -2,6 +2,8 @@ import Foundation
|
|||
|
||||
public enum LinkedItemFilter: String, CaseIterable {
|
||||
case inbox
|
||||
case readlater
|
||||
case newsletters
|
||||
case all
|
||||
case archived
|
||||
case files
|
||||
|
|
@ -12,6 +14,10 @@ public extension LinkedItemFilter {
|
|||
switch self {
|
||||
case .inbox:
|
||||
return "Inbox"
|
||||
case .readlater:
|
||||
return "Read Later"
|
||||
case .newsletters:
|
||||
return "Newsletters"
|
||||
case .all:
|
||||
return "All"
|
||||
case .archived:
|
||||
|
|
@ -25,6 +31,10 @@ public extension LinkedItemFilter {
|
|||
switch self {
|
||||
case .inbox:
|
||||
return "in:inbox"
|
||||
case .readlater:
|
||||
return "in:inbox -label:Newsletter"
|
||||
case .newsletters:
|
||||
return "in:inbox label:Newsletter"
|
||||
case .all:
|
||||
return "in:all"
|
||||
case .archived:
|
||||
|
|
@ -38,14 +48,22 @@ public extension LinkedItemFilter {
|
|||
let undeletedPredicate = NSPredicate(
|
||||
format: "%K != %i", #keyPath(LinkedItem.serverSyncStatus), Int64(ServerSyncStatus.needsDeletion.rawValue)
|
||||
)
|
||||
let notInArchivePredicate = NSPredicate(
|
||||
format: "%K == %@", #keyPath(LinkedItem.isArchived), Int(truncating: false) as NSNumber
|
||||
)
|
||||
|
||||
switch self {
|
||||
case .inbox:
|
||||
// non-archived items
|
||||
let notInArchivePredicate = NSPredicate(
|
||||
format: "%K == %@", #keyPath(LinkedItem.isArchived), Int(truncating: false) as NSNumber
|
||||
)
|
||||
return NSCompoundPredicate(andPredicateWithSubpredicates: [undeletedPredicate, notInArchivePredicate])
|
||||
case .readlater:
|
||||
// non-archived or deleted items without the Newsletter label
|
||||
let nonNewsletterLabelPredicate = NSPredicate(format: "NOT SUBQUERY(labels, $label, $label.name == \"Newsletter\") .@count > 0")
|
||||
return NSCompoundPredicate(andPredicateWithSubpredicates: [undeletedPredicate, notInArchivePredicate, nonNewsletterLabelPredicate])
|
||||
case .newsletters:
|
||||
// non-archived or deleted items with the Newsletter label
|
||||
let newsletterLabelPredicate = NSPredicate(format: "SUBQUERY(labels, $label, $label.name == \"Newsletter\").@count > 0")
|
||||
return NSCompoundPredicate(andPredicateWithSubpredicates: [notInArchivePredicate, newsletterLabelPredicate])
|
||||
case .all:
|
||||
// include everything undeleted
|
||||
return undeletedPredicate
|
||||
|
|
|
|||
Loading…
Reference in a new issue