Loading state

This commit is contained in:
Ali
2022-10-14 17:41:19 +04:00
parent 0128f6af0a
commit 8838fe095c
4 changed files with 90 additions and 53 deletions

View File

@@ -256,7 +256,7 @@ func chatListViewForLocation(chatListLocation: ChatListControllerLocation, locat
additionalItems: [],
hasEarlier: false,
hasLater: false,
isLoading: false
isLoading: view.isLoading
)
let type: ViewUpdateType

View File

@@ -30,6 +30,7 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
fileprivate let summaryComponents: ChatListEntrySummaryComponents
fileprivate var peer: Peer?
fileprivate var items: [Item] = []
fileprivate var isLoading: Bool = false
init(postbox: PostboxImpl, peerId: PeerId, summaryComponents: ChatListEntrySummaryComponents) {
self.peerId = peerId
@@ -43,6 +44,10 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
self.peer = postbox.peerTable.get(self.peerId)
let validIndexBoundary = postbox.peerThreadCombinedStateTable.get(peerId: peerId)?.validIndexBoundary
self.isLoading = validIndexBoundary == nil
if !self.isLoading {
let pinnedThreadIds = postbox.messageHistoryThreadPinnedTable.get(peerId: self.peerId)
var nextPinnedIndex = 0
@@ -100,11 +105,12 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
return lhs.index > rhs.index
})
}
}
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
var updated = false
if transaction.updatedMessageThreadPeerIds.contains(self.peerId) || transaction.updatedPinnedThreads.contains(self.peerId) || transaction.currentUpdatedMessageTagSummaries.contains(where: { $0.key.peerId == self.peerId }) || transaction.currentUpdatedMessageActionsSummaries.contains(where: { $0.key.peerId == self.peerId }) {
if transaction.updatedMessageThreadPeerIds.contains(self.peerId) || transaction.updatedPinnedThreads.contains(self.peerId) || transaction.updatedPeerThreadCombinedStates.contains(self.peerId) || transaction.currentUpdatedMessageTagSummaries.contains(where: { $0.key.peerId == self.peerId }) || transaction.currentUpdatedMessageActionsSummaries.contains(where: { $0.key.peerId == self.peerId }) {
self.reload(postbox: postbox)
updated = true
}
@@ -181,6 +187,7 @@ public final class EngineMessageHistoryThread {
public final class MessageHistoryThreadIndexView: PostboxView {
public let peer: Peer?
public let items: [EngineMessageHistoryThread.Item]
public let isLoading: Bool
init(_ view: MutableMessageHistoryThreadIndexView) {
self.peer = view.peer
@@ -197,6 +204,8 @@ public final class MessageHistoryThreadIndexView: PostboxView {
))
}
self.items = items
self.isLoading = view.isLoading
}
}

View File

@@ -34,8 +34,13 @@ public struct StoredPeerThreadCombinedState: Equatable, Codable {
case validIndexBoundary = "r"
}
var data: CodableEntry
var validIndexBoundary: Index?
public var data: CodableEntry
public var validIndexBoundary: Index?
public init(data: CodableEntry, validIndexBoundary: Index?) {
self.data = data
self.validIndexBoundary = validIndexBoundary
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

View File

@@ -160,6 +160,23 @@ struct StoreMessageHistoryThreadData {
var unreadReactionCount: Int32
}
struct PeerThreadCombinedState: Equatable, Codable {
var validIndexBoundary: StoredPeerThreadCombinedState.Index?
init(validIndexBoundary: StoredPeerThreadCombinedState.Index?) {
self.validIndexBoundary = validIndexBoundary
}
}
extension StoredPeerThreadCombinedState {
init?(_ state: PeerThreadCombinedState) {
guard let entry = CodableEntry(state) else {
return nil
}
self.init(data: entry, validIndexBoundary: state.validIndexBoundary)
}
}
public enum CreateForumChannelTopicError {
case generic
}
@@ -500,6 +517,12 @@ func _internal_loadMessageHistoryThreads(account: Account, peerId: PeerId) -> Si
} else {
transaction.setPeerPinnedThreads(peerId: peerId, threadIds: [])
}
if let entry = StoredPeerThreadCombinedState(PeerThreadCombinedState(
validIndexBoundary: StoredPeerThreadCombinedState.Index(timestamp: Int32.max, threadId: Int64(Int32.max), messageId: Int32.max)
)) {
transaction.setPeerThreadCombinedState(peerId: peerId, state: entry)
}
}
}
|> castError(LoadMessageHistoryThreadsError.self)