Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin 2021-02-16 21:18:58 +04:00
commit e3ca871a79
4 changed files with 87 additions and 26 deletions

View File

@ -463,7 +463,6 @@ public class GalleryController: ViewController, StandalonePresentableController
}
}
}
|> take(1)
let semaphore: DispatchSemaphore?
if synchronousLoad {
@ -487,6 +486,23 @@ public class GalleryController: ViewController, StandalonePresentableController
strongSelf.configuration = configuration
let entries = view.entries
if let centralEntryStableId = strongSelf.centralEntryStableId {
var found = false
for i in 0 ..< entries.count {
let message = entries[i].message
if message.stableId == centralEntryStableId {
found = true
break
}
}
if !found {
strongSelf.dismiss(forceAway: true)
return
}
}
var centralEntryStableId: UInt32?
loop: for i in 0 ..< entries.count {
let message = entries[i].message
@ -515,15 +531,17 @@ public class GalleryController: ViewController, StandalonePresentableController
strongSelf.entries = entries.reversed()
strongSelf.hasLeftEntries = view.hasLater
strongSelf.hasRightEntries = view.hasEarlier
if let centralEntryStableId = centralEntryStableId {
if strongSelf.centralEntryStableId == nil, let centralEntryStableId = centralEntryStableId {
strongSelf.centralEntryStableId = centralEntryStableId
}
} else {
strongSelf.entries = entries
strongSelf.hasLeftEntries = view.hasEarlier
strongSelf.hasRightEntries = view.hasLater
if strongSelf.centralEntryStableId == nil {
strongSelf.centralEntryStableId = centralEntryStableId
}
}
if strongSelf.isViewLoaded {
var items: [GalleryItem] = []
var centralItemIndex: Int?
@ -547,9 +565,12 @@ public class GalleryController: ViewController, StandalonePresentableController
strongSelf.galleryNode.pager.replaceItems(items, centralItemIndex: centralItemIndex)
if strongSelf.temporaryDoNotWaitForReady {
if !strongSelf.didSetReady {
strongSelf.didSetReady = true
strongSelf._ready.set(.single(true))
}
} else {
if !strongSelf.didSetReady {
let ready = strongSelf.galleryNode.pager.ready() |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(Void())) |> afterNext { [weak strongSelf] _ in
strongSelf?.didSetReady = true
}
@ -559,6 +580,7 @@ public class GalleryController: ViewController, StandalonePresentableController
}
}
}
}
var process = false
let _ = syncResult.modify { processed, _ in
if !processed {
@ -568,7 +590,7 @@ public class GalleryController: ViewController, StandalonePresentableController
return (true, nil)
}
semaphore?.signal()
if process {
if process || true {
Queue.mainQueue().async {
f()
}

View File

@ -1482,7 +1482,27 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
let baseNavigationController = self.baseNavigationController()
let mediaManager = self.context.sharedContext.mediaManager
var expandImpl: (() -> Void)?
let overlayNode = OverlayUniversalVideoNode(postbox: self.context.account.postbox, audioSession: context.sharedContext.mediaManager.audioSession, manager: context.sharedContext.mediaManager.universalVideoManager, content: item.content, expand: {
let shouldBeDismissed: Signal<Bool, NoError>
if let contentInfo = item.contentInfo, case let .message(message) = contentInfo {
let viewKey = PostboxViewKey.messages(Set([message.id]))
shouldBeDismissed = context.account.postbox.combinedView(keys: [viewKey])
|> map { views -> Bool in
guard let view = views.views[viewKey] as? MessagesView else {
return false
}
if view.messages.isEmpty {
return true
} else {
return false
}
}
|> distinctUntilChanged
} else {
shouldBeDismissed = .single(false)
}
let overlayNode = OverlayUniversalVideoNode(postbox: self.context.account.postbox, audioSession: context.sharedContext.mediaManager.audioSession, manager: context.sharedContext.mediaManager.universalVideoManager, content: item.content, shouldBeDismissed: shouldBeDismissed, expand: {
expandImpl?()
}, close: { [weak mediaManager] in
mediaManager?.setOverlayVideoNode(nil)

View File

@ -128,6 +128,7 @@ struct ChatHistoryView {
let associatedData: ChatMessageItemAssociatedData
let lastHeaderId: Int64
let id: Int32
let locationInput: ChatHistoryLocationInput?
}
enum ChatHistoryViewTransitionReason {
@ -705,7 +706,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
let currentViewVersion = Atomic<Int?>(value: nil)
let historyViewUpdate: Signal<(ChatHistoryViewUpdate, Int), NoError>
let historyViewUpdate: Signal<(ChatHistoryViewUpdate, Int, ChatHistoryLocationInput?), NoError>
var isFirstTime = true
if case let .custom(messages, at, _) = source {
historyViewUpdate = messages
@ -726,7 +727,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
scrollPosition = nil
}
return (ChatHistoryViewUpdate.HistoryView(view: MessageHistoryView(tagMask: nil, namespaces: .all, entries: messages.reversed().map { MessageHistoryEntry(message: $0, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)) }, holeEarlier: hasMore), type: .Generic(type: ViewUpdateType.Initial), scrollPosition: scrollPosition, flashIndicators: false, originalScrollPosition: nil, initialData: ChatHistoryCombinedInitialData(initialData: nil, buttonKeyboardMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil), id: 0), version)
return (ChatHistoryViewUpdate.HistoryView(view: MessageHistoryView(tagMask: nil, namespaces: .all, entries: messages.reversed().map { MessageHistoryEntry(message: $0, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)) }, holeEarlier: hasMore), type: .Generic(type: ViewUpdateType.Initial), scrollPosition: scrollPosition, flashIndicators: false, originalScrollPosition: nil, initialData: ChatHistoryCombinedInitialData(initialData: nil, buttonKeyboardMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil), id: 0), version, nil)
}
} else {
historyViewUpdate = self.chatHistoryLocationPromise.get()
@ -741,8 +742,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
break
}
}
}
|> map { view -> (ChatHistoryViewUpdate, Int) in
|> map { view -> (ChatHistoryViewUpdate, Int, ChatHistoryLocationInput?) in
let version = currentViewVersion.modify({ value in
if let value = value {
return value + 1
@ -750,7 +750,8 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
return 0
}
})!
return (view, version)
return (view, version, location)
}
}
}
@ -875,6 +876,10 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
func applyHole() {
Queue.mainQueue().async {
if let strongSelf = self {
if update.2 != strongSelf.chatHistoryLocationValue {
return
}
let historyView = (strongSelf.opaqueTransactionState as? ChatHistoryTransactionOpaqueState)?.historyView
let displayRange = strongSelf.displayedItemRange
if let filteredEntries = historyView?.filteredEntries, let visibleRange = displayRange.visibleRange {
@ -954,7 +959,7 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
let filteredEntries = chatHistoryEntriesForView(location: chatLocation, view: view, includeUnreadEntry: mode == .bubbles, includeEmptyEntry: mode == .bubbles && tagMask == nil, includeChatInfoEntry: mode == .bubbles, includeSearchEntry: includeSearchEntry && tagMask != nil, reverse: reverse, groupMessages: mode == .bubbles, selectedMessages: selectedMessages, presentationData: chatPresentationData, historyAppearsCleared: historyAppearsCleared, pendingUnpinnedAllMessages: pendingUnpinnedAllMessages, pendingRemovedMessages: pendingRemovedMessages, associatedData: associatedData, updatingMedia: updatingMedia, customChannelDiscussionReadState: customChannelDiscussionReadState, customThreadOutgoingReadState: customThreadOutgoingReadState)
let lastHeaderId = filteredEntries.last.flatMap { listMessageDateHeaderId(timestamp: $0.index.timestamp) } ?? 0
let processedView = ChatHistoryView(originalView: view, filteredEntries: filteredEntries, associatedData: associatedData, lastHeaderId: lastHeaderId, id: id)
let processedView = ChatHistoryView(originalView: view, filteredEntries: filteredEntries, associatedData: associatedData, lastHeaderId: lastHeaderId, id: id, locationInput: update.2)
let previousValueAndVersion = previousView.swap((processedView, update.1, selectedMessages))
let previous = previousValueAndVersion?.0
let previousSelectedMessages = previousValueAndVersion?.2
@ -1476,7 +1481,9 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
self.chatHistoryLocationValue = ChatHistoryLocationInput(content: locationInput, id: self.takeNextHistoryLocationId())
}
} else if loaded.firstIndex < 5, historyView.originalView.laterId == nil, !historyView.originalView.holeLater, let chatHistoryLocationValue = self.chatHistoryLocationValue, !chatHistoryLocationValue.isAtUpperBound, historyView.originalView.anchorIndex != .upperBound {
if self.chatHistoryLocationValue == historyView.locationInput {
self.chatHistoryLocationValue = ChatHistoryLocationInput(content: .Navigation(index: .upperBound, anchorIndex: .upperBound, count: historyMessageCount, highlight: false), id: self.takeNextHistoryLocationId())
}
} else if loaded.lastIndex >= historyView.filteredEntries.count - 5 && historyView.originalView.earlierId != nil {
let locationInput: ChatHistoryLocation = .Navigation(index: .message(firstEntry.index), anchorIndex: .message(firstEntry.index), count: historyMessageCount, highlight: false)
if self.chatHistoryLocationValue?.content != locationInput {

View File

@ -16,6 +16,8 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
private var validLayoutSize: CGSize?
private var shouldBeDismissedDisposable: Disposable?
override public var group: OverlayMediaItemNodeGroup? {
return OverlayMediaItemNodeGroup(rawValue: 0)
}
@ -35,7 +37,7 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
public var customClose: (() -> Void)?
public var controlsAreShowingUpdated: ((Bool) -> Void)?
public init(postbox: Postbox, audioSession: ManagedAudioSession, manager: UniversalVideoManager, content: UniversalVideoContent, expand: @escaping () -> Void, close: @escaping () -> Void) {
public init(postbox: Postbox, audioSession: ManagedAudioSession, manager: UniversalVideoManager, content: UniversalVideoContent, shouldBeDismissed: Signal<Bool, NoError> = .single(false), expand: @escaping () -> Void, close: @escaping () -> Void) {
self.content = content
self.defaultExpand = expand
@ -112,6 +114,16 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
}
self.videoNode.canAttachContent = true
self.shouldBeDismissedDisposable = (shouldBeDismissed
|> filter { $0 }
|> deliverOnMainQueue).start(next: { [weak self] _ in
guard let strongSelf = self else {
return
}
strongSelf.dismiss()
closeImpl?()
})
}
override public func didLoad() {