2024-02-26 17:12:34 +01:00
|
|
|
//
|
|
|
|
// SidebarItem.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 11/15/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Account
|
2024-03-21 04:49:15 +01:00
|
|
|
import Core
|
2024-02-26 17:12:34 +01:00
|
|
|
|
|
|
|
enum ReadFilterType {
|
|
|
|
case read
|
|
|
|
case none
|
|
|
|
case alwaysRead
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol SidebarItem: SidebarItemIdentifiable, ArticleFetcher, DisplayNameProvider, UnreadCountProvider {
|
|
|
|
|
|
|
|
var account: Account? { get }
|
2024-04-02 07:50:03 +02:00
|
|
|
@MainActor var defaultReadFilterType: ReadFilterType { get }
|
2024-02-26 17:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SidebarItem {
|
|
|
|
|
2024-04-02 07:50:03 +02:00
|
|
|
@MainActor func readFiltered(readFilterEnabledTable: [SidebarItemIdentifier: Bool]) -> Bool {
|
2024-02-26 17:12:34 +01:00
|
|
|
guard defaultReadFilterType != .alwaysRead else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if let sidebarItemID, let readFilterEnabled = readFilterEnabledTable[sidebarItemID] {
|
|
|
|
return readFilterEnabled
|
|
|
|
} else {
|
|
|
|
return defaultReadFilterType == .read
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Feed: SidebarItem {
|
|
|
|
|
|
|
|
var defaultReadFilterType: ReadFilterType {
|
|
|
|
return .none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Folder: SidebarItem {
|
|
|
|
|
|
|
|
var defaultReadFilterType: ReadFilterType {
|
|
|
|
return .read
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension AccountManager {
|
|
|
|
|
|
|
|
func existingSidebarItem(with sidebarItemID: SidebarItemIdentifier) -> SidebarItem? {
|
|
|
|
switch sidebarItemID {
|
|
|
|
case .folder(let accountID, let folderName):
|
|
|
|
if let account = existingAccount(with: accountID) {
|
|
|
|
return account.existingFolder(with: folderName)
|
|
|
|
}
|
|
|
|
case .feed(let accountID, let feedID):
|
|
|
|
if let account = existingAccount(with: accountID) {
|
|
|
|
return account.existingFeed(withFeedID: feedID)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|