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
|
|
|
}
|