mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
wip
This commit is contained in:
@@ -43,9 +43,23 @@ private func addTermItem(_ items: inout [TerminalItem], _ item: TerminalItem) {
|
||||
items.append(item)
|
||||
}
|
||||
|
||||
/// Represents a gap in a list of chat items, indicating where data is missing and should be loaded.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - itemId: The unique identifier of the last item in the loaded list before the gap.
|
||||
/// This ID corresponds to an item in the chat history, ordered from older to newer items.
|
||||
/// It is typically used when loading items via .around or .initial pagination when loading items
|
||||
/// - indexRange: The range of indexes within `reversedChatItems` array that
|
||||
/// represents the gap. The first index in this range is the position of the gap itself.
|
||||
/// For instance, if the array `[0, 1, 2, -100-, 101]` has a gap at index 3, `indexRange`
|
||||
/// would be `3..<5`, indicating the gap starts at index 3.
|
||||
/// - indexRangeInParentItems: The range of indexes in the `ReverseList` or parent UI component
|
||||
/// that considers revealed or hidden items, showing where the gap appears in the visible list.
|
||||
/// The first index in this range points to where the gap starts in the UI.
|
||||
struct ChatGap {
|
||||
let index: Int
|
||||
let size: Int
|
||||
let itemId: Int64
|
||||
let indexRange: Range<Int>
|
||||
let indexRangeInParentItems: Range<Int>
|
||||
}
|
||||
|
||||
class ItemsModel: ObservableObject {
|
||||
@@ -63,14 +77,12 @@ class ItemsModel: ObservableObject {
|
||||
var itemAdded = false {
|
||||
willSet { publisher.send() }
|
||||
}
|
||||
var gap: ChatGap? = nil {
|
||||
willSet { publisher.send() }
|
||||
}
|
||||
|
||||
// Publishes directly to `objectWillChange` publisher,
|
||||
// this will cause reversedChatItems to be rendered without throttling
|
||||
@Published var isLoading = false
|
||||
@Published var showLoadingProgress = false
|
||||
@State var gaps: [ChatItem.ID] = []
|
||||
|
||||
init() {
|
||||
publisher
|
||||
@@ -99,7 +111,9 @@ class ItemsModel: ObservableObject {
|
||||
if let chat = ChatModel.shared.getChat(chatId) {
|
||||
await MainActor.run { self.isLoading = true }
|
||||
// try? await Task.sleep(nanoseconds: 5000_000000)
|
||||
await loadChat(chat: chat)
|
||||
if let gap = await loadChat(chat: chat) {
|
||||
self.gaps = [gap]
|
||||
}
|
||||
navigationTimeout.cancel()
|
||||
progressTimeout.cancel()
|
||||
await MainActor.run {
|
||||
|
||||
Reference in New Issue
Block a user