mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Dismiss gallery when currently displayed entry becomes deleted
This commit is contained in:
parent
2c6c7e23d6
commit
9e7c9abceb
@ -463,7 +463,6 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> take(1)
|
|
||||||
|
|
||||||
let semaphore: DispatchSemaphore?
|
let semaphore: DispatchSemaphore?
|
||||||
if synchronousLoad {
|
if synchronousLoad {
|
||||||
@ -487,6 +486,23 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||||||
strongSelf.configuration = configuration
|
strongSelf.configuration = configuration
|
||||||
|
|
||||||
let entries = view.entries
|
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?
|
var centralEntryStableId: UInt32?
|
||||||
loop: for i in 0 ..< entries.count {
|
loop: for i in 0 ..< entries.count {
|
||||||
let message = entries[i].message
|
let message = entries[i].message
|
||||||
@ -515,14 +531,16 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||||||
strongSelf.entries = entries.reversed()
|
strongSelf.entries = entries.reversed()
|
||||||
strongSelf.hasLeftEntries = view.hasLater
|
strongSelf.hasLeftEntries = view.hasLater
|
||||||
strongSelf.hasRightEntries = view.hasEarlier
|
strongSelf.hasRightEntries = view.hasEarlier
|
||||||
if let centralEntryStableId = centralEntryStableId {
|
if strongSelf.centralEntryStableId == nil, let centralEntryStableId = centralEntryStableId {
|
||||||
strongSelf.centralEntryStableId = centralEntryStableId
|
strongSelf.centralEntryStableId = centralEntryStableId
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
strongSelf.entries = entries
|
strongSelf.entries = entries
|
||||||
strongSelf.hasLeftEntries = view.hasEarlier
|
strongSelf.hasLeftEntries = view.hasEarlier
|
||||||
strongSelf.hasRightEntries = view.hasLater
|
strongSelf.hasRightEntries = view.hasLater
|
||||||
strongSelf.centralEntryStableId = centralEntryStableId
|
if strongSelf.centralEntryStableId == nil {
|
||||||
|
strongSelf.centralEntryStableId = centralEntryStableId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if strongSelf.isViewLoaded {
|
if strongSelf.isViewLoaded {
|
||||||
var items: [GalleryItem] = []
|
var items: [GalleryItem] = []
|
||||||
@ -547,13 +565,17 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||||||
strongSelf.galleryNode.pager.replaceItems(items, centralItemIndex: centralItemIndex)
|
strongSelf.galleryNode.pager.replaceItems(items, centralItemIndex: centralItemIndex)
|
||||||
|
|
||||||
if strongSelf.temporaryDoNotWaitForReady {
|
if strongSelf.temporaryDoNotWaitForReady {
|
||||||
strongSelf.didSetReady = true
|
if !strongSelf.didSetReady {
|
||||||
strongSelf._ready.set(.single(true))
|
strongSelf.didSetReady = true
|
||||||
} else {
|
strongSelf._ready.set(.single(true))
|
||||||
let ready = strongSelf.galleryNode.pager.ready() |> timeout(2.0, queue: Queue.mainQueue(), alternate: .single(Void())) |> afterNext { [weak strongSelf] _ in
|
}
|
||||||
strongSelf?.didSetReady = 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
|
||||||
|
}
|
||||||
|
strongSelf._ready.set(ready |> map { true })
|
||||||
}
|
}
|
||||||
strongSelf._ready.set(ready |> map { true })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -568,7 +590,7 @@ public class GalleryController: ViewController, StandalonePresentableController
|
|||||||
return (true, nil)
|
return (true, nil)
|
||||||
}
|
}
|
||||||
semaphore?.signal()
|
semaphore?.signal()
|
||||||
if process {
|
if process || true {
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
@ -1482,7 +1482,27 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
|
|||||||
let baseNavigationController = self.baseNavigationController()
|
let baseNavigationController = self.baseNavigationController()
|
||||||
let mediaManager = self.context.sharedContext.mediaManager
|
let mediaManager = self.context.sharedContext.mediaManager
|
||||||
var expandImpl: (() -> Void)?
|
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?()
|
expandImpl?()
|
||||||
}, close: { [weak mediaManager] in
|
}, close: { [weak mediaManager] in
|
||||||
mediaManager?.setOverlayVideoNode(nil)
|
mediaManager?.setOverlayVideoNode(nil)
|
||||||
|
@ -16,6 +16,8 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
|
|||||||
|
|
||||||
private var validLayoutSize: CGSize?
|
private var validLayoutSize: CGSize?
|
||||||
|
|
||||||
|
private var shouldBeDismissedDisposable: Disposable?
|
||||||
|
|
||||||
override public var group: OverlayMediaItemNodeGroup? {
|
override public var group: OverlayMediaItemNodeGroup? {
|
||||||
return OverlayMediaItemNodeGroup(rawValue: 0)
|
return OverlayMediaItemNodeGroup(rawValue: 0)
|
||||||
}
|
}
|
||||||
@ -35,7 +37,7 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
|
|||||||
public var customClose: (() -> Void)?
|
public var customClose: (() -> Void)?
|
||||||
public var controlsAreShowingUpdated: ((Bool) -> 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.content = content
|
||||||
self.defaultExpand = expand
|
self.defaultExpand = expand
|
||||||
|
|
||||||
@ -112,6 +114,16 @@ public final class OverlayUniversalVideoNode: OverlayMediaItemNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.videoNode.canAttachContent = true
|
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() {
|
override public func didLoad() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user