[WIP] Saved messages

This commit is contained in:
Isaac
2023-12-25 22:58:09 +04:00
parent 4651c39083
commit 0e75f18f14
65 changed files with 934 additions and 369 deletions

View File

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