mirror of
https://github.com/yattee/yattee.git
synced 2025-12-03 22:58:16 +00:00
Feed count model
This commit is contained in:
32
Model/UnwatchedFeedCountModel.swift
Normal file
32
Model/UnwatchedFeedCountModel.swift
Normal file
@@ -0,0 +1,32 @@
|
||||
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
|
||||
|
||||
var unwatchedText: Text? {
|
||||
if let account = accounts.current,
|
||||
!account.anonymous,
|
||||
let count = unwatched[account]
|
||||
{
|
||||
return Text(String(count))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func unwatchedByChannelText(_ channel: Channel) -> Text? {
|
||||
if let account = accounts.current,
|
||||
!account.anonymous,
|
||||
let count = unwatchedByChannel[account]?[channel.id]
|
||||
{
|
||||
return Text(String(count))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user