1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30
yattee/Model/UnwatchedFeedCountModel.swift

37 lines
947 B
Swift
Raw Normal View History

2022-12-17 02:56:14 +05:30
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-19 00:09:03 +05:30
// swiftlint:disable empty_count
2022-12-17 02:56:14 +05:30
var unwatchedText: Text? {
if let account = accounts.current,
!account.anonymous,
2022-12-19 00:09:03 +05:30
let count = unwatched[account],
count > 0
2022-12-17 02:56:14 +05:30
{
return Text(String(count))
}
return nil
}
func unwatchedByChannelText(_ channel: Channel) -> Text? {
if let account = accounts.current,
!account.anonymous,
2022-12-19 00:09:03 +05:30
let count = unwatchedByChannel[account]?[channel.id],
count > 0
2022-12-17 02:56:14 +05:30
{
return Text(String(count))
}
return nil
}
2023-04-22 18:38:33 +05:30
// swiftlint:enable empty_count
2022-12-17 02:56:14 +05:30
}