yattee/Model/UnwatchedFeedCountModel.swift

37 lines
947 B
Swift
Raw Normal View History

2022-12-16 21:26:14 +00:00
import Foundation
import SwiftUI
final class UnwatchedFeedCountModel: ObservableObject {
static let shared = UnwatchedFeedCountModel()
@Published var unwatched = [Account: Int]()
@Published var unwatchedByChannel = [Account: [Channel.ID: Int]]()
private var accounts = AccountsModel.shared
2022-12-18 18:39:03 +00:00
// swiftlint:disable empty_count
2022-12-16 21:26:14 +00:00
var unwatchedText: Text? {
if let account = accounts.current,
!account.anonymous,
2022-12-18 18:39:03 +00:00
let count = unwatched[account],
count > 0
2022-12-16 21:26:14 +00:00
{
return Text(String(count))
}
return nil
}
func unwatchedByChannelText(_ channel: Channel) -> Text? {
if let account = accounts.current,
!account.anonymous,
2022-12-18 18:39:03 +00:00
let count = unwatchedByChannel[account]?[channel.id],
count > 0
2022-12-16 21:26:14 +00:00
{
return Text(String(count))
}
return nil
}
2023-04-22 13:08:33 +00:00
// swiftlint:enable empty_count
2022-12-16 21:26:14 +00:00
}