mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Reset history view after history hole updates
This commit is contained in:
parent
5ab1ec2251
commit
d0f1dc5dad
File diff suppressed because it is too large
Load Diff
@ -15,9 +15,13 @@ public struct HolesViewMedia: Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct MessageOfInterestHole: Hashable, Equatable {
|
||||
public struct MessageOfInterestHole: Hashable, Equatable, CustomStringConvertible {
|
||||
public let hole: MessageHistoryViewHole
|
||||
public let direction: MessageHistoryViewRelativeHoleDirection
|
||||
|
||||
public var description: String {
|
||||
return "hole: \(self.hole), direction: \(self.direction)"
|
||||
}
|
||||
}
|
||||
|
||||
public enum MessageOfInterestViewLocation: Hashable {
|
||||
@ -29,6 +33,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
private let count: Int
|
||||
private var anchor: HistoryViewInputAnchor
|
||||
private var wrappedView: MutableMessageHistoryView
|
||||
private var peerIds: MessageHistoryViewPeerIds
|
||||
|
||||
fileprivate var closestHole: MessageOfInterestHole?
|
||||
fileprivate var closestLaterMedia: [HolesViewMedia] = []
|
||||
@ -44,6 +49,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
mainPeerId = id
|
||||
peerIds = postbox.peerIdsForLocation(.peer(id), tagMask: nil)
|
||||
}
|
||||
self.peerIds = peerIds
|
||||
var anchor: HistoryViewInputAnchor = .upperBound
|
||||
if let combinedState = postbox.readStateTable.getCombinedState(mainPeerId), let state = combinedState.states.first, state.1.count != 0 {
|
||||
switch state.1 {
|
||||
@ -107,7 +113,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
}
|
||||
var anchor: HistoryViewInputAnchor = self.anchor
|
||||
if transaction.alteredInitialPeerCombinedReadStates[peerId] != nil {
|
||||
var anchor: HistoryViewInputAnchor = .upperBound
|
||||
var updatedAnchor: HistoryViewInputAnchor = .upperBound
|
||||
if let combinedState = postbox.readStateTable.getCombinedState(peerId), let state = combinedState.states.first, state.1.count != 0 {
|
||||
switch state.1 {
|
||||
case let .idBased(maxIncomingReadId, _, _, _, _):
|
||||
@ -116,6 +122,7 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
anchor = .index(maxIncomingReadIndex)
|
||||
}
|
||||
}
|
||||
anchor = updatedAnchor
|
||||
}
|
||||
|
||||
if self.anchor != anchor {
|
||||
@ -128,6 +135,34 @@ final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
self.wrappedView = MutableMessageHistoryView(postbox: postbox, orderStatistics: [], peerIds: peerIds, anchor: self.anchor, combinedReadStates: nil, transientReadStates: nil, tag: nil, namespaces: .all, count: self.count, topTaggedMessages: [:], additionalDatas: [], getMessageCountInRange: { _, _ in return 0})
|
||||
return self.updateFromView()
|
||||
} else if self.wrappedView.replay(postbox: postbox, transaction: transaction) {
|
||||
var reloadView = false
|
||||
if !transaction.currentPeerHoleOperations.isEmpty {
|
||||
var allPeerIds: [PeerId]
|
||||
switch peerIds {
|
||||
case let .single(peerId):
|
||||
allPeerIds = [peerId]
|
||||
case let .associated(peerId, attachedMessageId):
|
||||
allPeerIds = [peerId]
|
||||
if let attachedMessageId = attachedMessageId {
|
||||
allPeerIds.append(attachedMessageId.peerId)
|
||||
}
|
||||
}
|
||||
for (key, _) in transaction.currentPeerHoleOperations {
|
||||
if allPeerIds.contains(key.peerId) {
|
||||
reloadView = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if reloadView {
|
||||
let peerIds: MessageHistoryViewPeerIds
|
||||
switch self.location {
|
||||
case let .peer(id):
|
||||
peerIds = postbox.peerIdsForLocation(.peer(id), tagMask: nil)
|
||||
}
|
||||
self.wrappedView = MutableMessageHistoryView(postbox: postbox, orderStatistics: [], peerIds: peerIds, anchor: self.anchor, combinedReadStates: nil, transientReadStates: nil, tag: nil, namespaces: .all, count: self.count, topTaggedMessages: [:], additionalDatas: [], getMessageCountInRange: { _, _ in return 0})
|
||||
}
|
||||
|
||||
return self.updateFromView()
|
||||
} else {
|
||||
return false
|
||||
|
@ -671,7 +671,7 @@ private func settingsEntries(account: Account, presentationData: PresentationDat
|
||||
entries.append(.savedMessages(presentationData.theme, PresentationResourcesSettings.savedMessages, presentationData.strings.Settings_SavedMessages))
|
||||
entries.append(.recentCalls(presentationData.theme, PresentationResourcesSettings.recentCalls, presentationData.strings.CallSettings_RecentCalls))
|
||||
if enableQRLogin {
|
||||
entries.append(.devices(presentationData.theme, UIImage(bundleImageName: "Settings/MenuIcons/Sessions")?.precomposed(), presentationData.strings.Settings_Devices, otherSessionCount == 0 ? presentationData.strings.Settings_AddDevice : "\(otherSessionCount)"))
|
||||
entries.append(.devices(presentationData.theme, UIImage(bundleImageName: "Settings/MenuIcons/Sessions")?.precomposed(), presentationData.strings.Settings_Devices, otherSessionCount == 0 ? presentationData.strings.Settings_AddDevice : "\(otherSessionCount + 1)"))
|
||||
} else {
|
||||
entries.append(.stickers(presentationData.theme, PresentationResourcesSettings.stickers, presentationData.strings.ChatSettings_Stickers, unreadTrendingStickerPacks == 0 ? "" : "\(unreadTrendingStickerPacks)", archivedPacks))
|
||||
}
|
||||
|
@ -1761,7 +1761,13 @@ private func resetChannels(network: Network, peers: [Peer], state: AccountMutabl
|
||||
|
||||
private func pollChannel(network: Network, peer: Peer, state: AccountMutableState) -> Signal<(AccountMutableState, Bool, Int32?), NoError> {
|
||||
if let inputChannel = apiInputChannel(peer) {
|
||||
let limit: Int32 = 20
|
||||
let limit: Int32
|
||||
#if DEBUG
|
||||
limit = 1
|
||||
#else
|
||||
limit = 20
|
||||
#endif
|
||||
|
||||
let pollPts: Int32
|
||||
if let channelState = state.chatStates[peer.id] as? ChannelState {
|
||||
pollPts = channelState.pts
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user