mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[WIP] Saved messages
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user