mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
56 lines
1.6 KiB
Swift
56 lines
1.6 KiB
Swift
import Foundation
|
|
|
|
final class MutableMessageHistorySavedMessagesStatsView: MutablePostboxView {
|
|
fileprivate let peerId: PeerId
|
|
fileprivate var count: Int = 0
|
|
fileprivate var isLoading: Bool = false
|
|
|
|
init(postbox: PostboxImpl, peerId: PeerId) {
|
|
self.peerId = peerId
|
|
|
|
self.reload(postbox: postbox)
|
|
}
|
|
|
|
private func reload(postbox: PostboxImpl) {
|
|
let validIndexBoundary = postbox.peerThreadCombinedStateTable.get(peerId: peerId)?.validIndexBoundary
|
|
self.isLoading = validIndexBoundary == nil
|
|
|
|
if !self.isLoading {
|
|
self.count = postbox.messageHistoryThreadIndexTable.getCount(peerId: self.peerId)
|
|
} else {
|
|
self.count = 0
|
|
}
|
|
}
|
|
|
|
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
|
var updated = false
|
|
|
|
if transaction.updatedMessageThreadPeerIds.contains(self.peerId) {
|
|
self.reload(postbox: postbox)
|
|
updated = true
|
|
}
|
|
|
|
return updated
|
|
}
|
|
|
|
func refreshDueToExternalTransaction(postbox: PostboxImpl) -> Bool {
|
|
self.reload(postbox: postbox)
|
|
|
|
return true
|
|
}
|
|
|
|
func immutableView() -> PostboxView {
|
|
return MessageHistorySavedMessagesStatsView(self)
|
|
}
|
|
}
|
|
|
|
public final class MessageHistorySavedMessagesStatsView: PostboxView {
|
|
public let isLoading: Bool
|
|
public let count: Int
|
|
|
|
init(_ view: MutableMessageHistorySavedMessagesStatsView) {
|
|
self.isLoading = view.isLoading
|
|
self.count = view.count
|
|
}
|
|
}
|