diff --git a/submodules/Postbox/Sources/MessageHistoryViewState.swift b/submodules/Postbox/Sources/MessageHistoryViewState.swift index c5cb3a70c2..1fb2892f30 100644 --- a/submodules/Postbox/Sources/MessageHistoryViewState.swift +++ b/submodules/Postbox/Sources/MessageHistoryViewState.swift @@ -2082,7 +2082,7 @@ enum HistoryViewState { init(postbox: PostboxImpl, inputAnchor: HistoryViewInputAnchor, tag: HistoryViewInputTag?, appendMessagesFromTheSameGroup: Bool, namespaces: MessageIdNamespaces, statistics: MessageHistoryViewOrderStatistics, ignoreMessagesInTimestampRange: ClosedRange?, halfLimit: Int, locations: MessageHistoryViewInput) { switch inputAnchor { case let .index(index): - self = .loaded(HistoryViewLoadedState(anchor: .index(index), tag: tag, appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, namespaces: namespaces, statistics: statistics, ignoreMessagesInTimestampRange: ignoreMessagesInTimestampRange, halfLimit: halfLimit, locations: locations, postbox: postbox, holes: HistoryViewHoles(holesBySpace: fetchHoles(postbox: postbox, locations: locations, tag: tag, namespaces: namespaces)))) + self = .loaded(HistoryViewLoadedState(anchor: .index(index), tag: tag, appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, namespaces: namespaces, statistics: statistics, ignoreMessagesInTimestampRange: ignoreMessagesInTimestampRange, halfLimit: halfLimit, locations: locations, postbox: postbox, holes: HistoryViewHoles(holesBySpace: fetchHoles(postbox: postbox, locations: locations, tag: tag, namespaces: namespaces)))) case .lowerBound: self = .loaded(HistoryViewLoadedState(anchor: .lowerBound, tag: tag, appendMessagesFromTheSameGroup: appendMessagesFromTheSameGroup, namespaces: namespaces, statistics: statistics, ignoreMessagesInTimestampRange: ignoreMessagesInTimestampRange, halfLimit: halfLimit, locations: locations, postbox: postbox, holes: HistoryViewHoles(holesBySpace: fetchHoles(postbox: postbox, locations: locations, tag: tag, namespaces: namespaces)))) case .upperBound: diff --git a/submodules/TelegramCore/Sources/State/Holes.swift b/submodules/TelegramCore/Sources/State/Holes.swift index 3e08ccd116..5ba4679264 100644 --- a/submodules/TelegramCore/Sources/State/Holes.swift +++ b/submodules/TelegramCore/Sources/State/Holes.swift @@ -950,7 +950,15 @@ func fetchMessageHistoryHole(accountPeerId: PeerId, source: FetchMessageHistoryH case let .aroundId(aroundId): filledRange = min(aroundId.id, messageRange.lowerBound) ... max(aroundId.id, messageRange.upperBound) strictFilledIndices = IndexSet(integersIn: Int(min(aroundId.id, messageRange.lowerBound)) ... Int(max(aroundId.id, messageRange.upperBound))) + var shouldFillAround = false if peerInput.requestThreadId(accountPeerId: accountPeerId) != nil { + shouldFillAround = true + } + if case .customTag = space { + shouldFillAround = true + } + + if shouldFillAround { if ids.count <= count / 2 - 1 { filledRange = minMaxRange } diff --git a/submodules/TelegramCore/Sources/State/ManagedMessageHistoryHoles.swift b/submodules/TelegramCore/Sources/State/ManagedMessageHistoryHoles.swift index e6ab49dae5..efe3ecc81f 100644 --- a/submodules/TelegramCore/Sources/State/ManagedMessageHistoryHoles.swift +++ b/submodules/TelegramCore/Sources/State/ManagedMessageHistoryHoles.swift @@ -157,8 +157,11 @@ private final class ManagedMessageHistoryHolesContext { }*/ for entry in entries { - if self.completedEntries[entry] != nil { - continue + if let previousTimestamp = self.completedEntries[entry] { + if previousTimestamp >= CFAbsoluteTimeGetCurrent() - 20.0 { + Logger.shared.log("ManagedMessageHistoryHoles", "Not adding recently finished entry \(entry)") + continue + } } switch entry.hole { diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index b14d945d1e..3fd70d1b20 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -2539,7 +2539,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { return } inlineSearchResultsView.alpha = 1.0 - inlineSearchResultsView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25) + inlineSearchResultsView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) inlineSearchResultsView.animateIn() transition.updateSublayerTransformScale(node: self.historyNodeContainer, scale: CGPoint(x: 0.95, y: 0.95)) diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index 4668d3855d..f108e88d3d 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -5,6 +5,7 @@ import SwiftSignalKit import Display import AsyncDisplayKit import TelegramCore +import Postbox import TelegramPresentationData import TelegramUIPreferences import MediaResources @@ -1560,6 +1561,59 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto } initialData = combinedInitialData + + if resetScrolling, let previousViewValue = previousView.with({ $0 })?.0 { + let filteredEntries: [ChatHistoryEntry] = [] + let processedView = ChatHistoryView(originalView: MessageHistoryView(tag: nil, namespaces: .all, entries: [], holeEarlier: false, holeLater: false, isLoading: true), filteredEntries: filteredEntries, associatedData: previousViewValue.associatedData, lastHeaderId: 0, id: previousViewValue.id, locationInput: previousViewValue.locationInput, ignoreMessagesInTimestampRange: nil) + let previousValueAndVersion = previousView.swap((processedView, update.1, selectedMessages, allAdMessages.version)) + let previous = previousValueAndVersion?.0 + let previousSelectedMessages = previousValueAndVersion?.2 + + if let previousVersion = previousValueAndVersion?.1 { + assert(update.1 >= previousVersion) + } + + var reason: ChatHistoryViewTransitionReason + reason = ChatHistoryViewTransitionReason.InteractiveChanges + + let disableAnimations = true + let forceSynchronous = true + + let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: false, chatLocation: chatLocation, controllerInteraction: controllerInteraction, scrollPosition: nil, scrollAnimationCurve: nil, initialData: initialData?.initialData, keyboardButtonsMessage: nil, cachedData: initialData?.cachedData, cachedDataMessages: initialData?.cachedDataMessages, readStateData: initialData?.readStateData, flashIndicators: false, updatedMessageSelection: previousSelectedMessages != selectedMessages, messageTransitionNode: messageTransitionNode(), allUpdated: false) + var mappedTransition = mappedChatHistoryViewListTransition(context: context, chatLocation: chatLocation, associatedData: previousViewValue.associatedData, controllerInteraction: controllerInteraction, mode: mode, lastHeaderId: 0, animateFromPreviousFilter: resetScrolling, transition: rawTransition) + + if disableAnimations { + mappedTransition.options.remove(.AnimateInsertion) + mappedTransition.options.remove(.AnimateAlpha) + mappedTransition.options.remove(.AnimateTopItemPosition) + mappedTransition.options.remove(.RequestItemInsertionAnimations) + } + if forceSynchronous || resetScrolling { + mappedTransition.options.insert(.Synchronous) + } + if resetScrolling { + mappedTransition.options.insert(.AnimateAlpha) + mappedTransition.options.insert(.AnimateFullTransition) + } + + if resetScrolling { + resetScrolling = false + } + + Queue.mainQueue().async { + guard let strongSelf = self else { + return + } + if strongSelf.appliedPlayingMessageId?.0 != currentlyPlayingMessageIdAndType?.0 { + strongSelf.appliedPlayingMessageId = currentlyPlayingMessageIdAndType + } + if strongSelf.appliedScrollToMessageId != scrollToMessageId { + strongSelf.appliedScrollToMessageId = scrollToMessageId + } + strongSelf.enqueueHistoryViewTransition(mappedTransition) + } + } + Queue.mainQueue().async { if let strongSelf = self { if !strongSelf.didSetInitialData { diff --git a/submodules/TelegramUI/Sources/ChatHistoryViewForLocation.swift b/submodules/TelegramUI/Sources/ChatHistoryViewForLocation.swift index 4931b92c21..7bcdd05c3b 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryViewForLocation.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryViewForLocation.swift @@ -37,6 +37,8 @@ func preloadedChatHistoryViewForLocation(_ location: ChatHistoryLocationInput, c } func chatHistoryViewForLocation(_ location: ChatHistoryLocationInput, ignoreMessagesInTimestampRange: ClosedRange?, context: AccountContext, chatLocation: ChatLocation, chatLocationContextHolder: Atomic, scheduled: Bool, fixedCombinedReadStates: MessageHistoryViewReadState?, tag: HistoryViewInputTag?, appendMessagesFromTheSameGroup: Bool, additionalData: [AdditionalMessageHistoryViewData], orderStatistics: MessageHistoryViewOrderStatistics = []) -> Signal { + print("request \(location.content)") + let account = context.account if scheduled { var first = true @@ -93,7 +95,7 @@ func chatHistoryViewForLocation(_ location: ChatHistoryLocationInput, ignoreMess let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData) - if preloaded { + if preloaded { return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id) } else { if view.isLoading {