Reset history view after history hole updates

This commit is contained in:
Ali
2019-12-09 15:34:30 +04:00
parent 5ab1ec2251
commit d0f1dc5dad
5 changed files with 522 additions and 435 deletions

View File

@@ -4,7 +4,7 @@ import SwiftSignalKit
import SyncCore
public struct HistoryPreloadIndex: Comparable {
public struct HistoryPreloadIndex: Comparable, CustomStringConvertible {
public let index: ChatListIndex?
public let hasUnread: Bool
public let isMuted: Bool
@@ -49,9 +49,13 @@ public struct HistoryPreloadIndex: Comparable {
return true
}
}
public var description: String {
return "index: \(String(describing: self.index)), hasUnread: \(self.hasUnread), isMuted: \(self.isMuted), isPriority: \(self.isPriority)"
}
}
private struct HistoryPreloadHole: Hashable, Comparable {
private struct HistoryPreloadHole: Hashable, Comparable, CustomStringConvertible {
let preloadIndex: HistoryPreloadIndex
let hole: MessageOfInterestHole
@@ -66,6 +70,10 @@ private struct HistoryPreloadHole: Hashable, Comparable {
var hashValue: Int {
return self.preloadIndex.index.hashValue &* 31 &+ self.hole.hashValue
}
var description: String {
return "(preloadIndex: \(self.preloadIndex), hole: \(self.hole))"
}
}
private final class HistoryPreloadEntry: Comparable {
@@ -90,6 +98,9 @@ private final class HistoryPreloadEntry: Comparable {
self.isStarted = true
let hole = self.hole.hole
Logger.shared.log("HistoryPreload", "start hole \(hole)")
let signal: Signal<Never, NoError> = .complete()
|> delay(0.3, queue: queue)
|> then(
@@ -98,8 +109,8 @@ private final class HistoryPreloadEntry: Comparable {
|> deliverOn(queue)
|> mapToSignal { download -> Signal<Never, NoError> in
switch hole.hole {
case let .peer(peerHole):
return fetchMessageHistoryHole(accountPeerId: accountPeerId, source: .download(download), postbox: postbox, peerId: peerHole.peerId, namespace: peerHole.namespace, direction: hole.direction, space: .everywhere, count: 60)
case let .peer(peerHole):
return fetchMessageHistoryHole(accountPeerId: accountPeerId, source: .download(download), postbox: postbox, peerId: peerHole.peerId, namespace: peerHole.namespace, direction: hole.direction, space: .everywhere, count: 60)
}
}
)
@@ -421,6 +432,14 @@ final class ChatHistoryPreloadManager {
}
let updatedHole = view.currentHole
let holeIsUpdated = previousHole != updatedHole
switch index.entity {
case let .peer(peerId):
Logger.shared.log("HistoryPreload", "view \(peerId) hole \(updatedHole) isUpdated: \(holeIsUpdated)")
}
if previousHole != updatedHole {
strongSelf.update(from: previousHole, to: updatedHole)
}
@@ -448,7 +467,11 @@ final class ChatHistoryPreloadManager {
private func update(from previousHole: HistoryPreloadHole?, to updatedHole: HistoryPreloadHole?) {
assert(self.queue.isCurrent())
if previousHole == updatedHole {
let isHoleUpdated = previousHole != updatedHole
Logger.shared.log("HistoryPreload", "update from \(String(describing: previousHole)) to \(String(describing: updatedHole)), isUpdated: \(isHoleUpdated)")
if !isHoleUpdated {
return
}
@@ -482,9 +505,12 @@ final class ChatHistoryPreloadManager {
}
if self.canPreloadHistoryValue {
Logger.shared.log("HistoryPreload", "will start")
for i in 0 ..< min(3, self.entries.count) {
self.entries[i].startIfNeeded(postbox: self.postbox, accountPeerId: self.accountPeerId, download: self.download.get() |> take(1), queue: self.queue)
}
} else {
Logger.shared.log("HistoryPreload", "will not start, canPreloadHistoryValue = false")
}
}
}