mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
no message
This commit is contained in:
@@ -6,52 +6,20 @@ import TelegramCore
|
||||
import SwiftSignalKit
|
||||
|
||||
final class ChatMediaInputGifPane: ASDisplayNode, UIScrollViewDelegate {
|
||||
private let multiplexedNode: MultiplexedVideoNode
|
||||
private let account: Account
|
||||
private let controllerInteraction: ChatControllerInteraction
|
||||
|
||||
private var multiplexedNode: MultiplexedVideoNode?
|
||||
|
||||
private let disposable = MetaDisposable()
|
||||
|
||||
private var validLayout: CGSize?
|
||||
|
||||
init(account: Account, controllerInteraction: ChatControllerInteraction) {
|
||||
self.multiplexedNode = MultiplexedVideoNode(account: account)
|
||||
self.account = account
|
||||
self.controllerInteraction = controllerInteraction
|
||||
|
||||
super.init()
|
||||
|
||||
self.view.addSubview(self.multiplexedNode)
|
||||
let initialOrder = Atomic<[MediaId]?>(value: nil)
|
||||
let gifs = account.postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)])
|
||||
|> map { view -> [TelegramMediaFile] in
|
||||
var recentGifs: OrderedItemListView?
|
||||
if let orderedView = view.views[.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)] {
|
||||
recentGifs = orderedView as? OrderedItemListView
|
||||
}
|
||||
if let recentGifs = recentGifs {
|
||||
return recentGifs.items.map { ($0.contents as! RecentMediaItem).media as! TelegramMediaFile }
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
self.disposable.set((gifs |> deliverOnMainQueue).start(next: { [weak self] gifs in
|
||||
if let strongSelf = self {
|
||||
strongSelf.multiplexedNode.files = gifs
|
||||
}
|
||||
}))
|
||||
|
||||
self.multiplexedNode.fileSelected = { file in
|
||||
controllerInteraction.sendGif(file)
|
||||
}
|
||||
self.multiplexedNode.fileLongPressed = { [weak self] file in
|
||||
if let strongSelf = self, let itemFrame = strongSelf.multiplexedNode.frameForItem(file.fileId) {
|
||||
let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text("Delete"), action: {
|
||||
let _ = removeSavedGif(postbox: account.postbox, mediaId: file.fileId).start()
|
||||
})])
|
||||
controllerInteraction.presentController(contextMenuController, ContextMenuControllerPresentationArguments(sourceNodeAndRect: {
|
||||
if let strongSelf = self {
|
||||
return (strongSelf, strongSelf.multiplexedNode.convert(itemFrame, to: strongSelf.view).insetBy(dx: -2.0, dy: -2.0).offsetBy(dx: strongSelf.multiplexedNode.frame.minX, dy: strongSelf.multiplexedNode.frame.minY))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
@@ -59,6 +27,60 @@ final class ChatMediaInputGifPane: ASDisplayNode, UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) {
|
||||
self.multiplexedNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))
|
||||
self.validLayout = size
|
||||
self.multiplexedNode?.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.height))
|
||||
}
|
||||
|
||||
override func willEnterHierarchy() {
|
||||
super.willEnterHierarchy()
|
||||
|
||||
if self.multiplexedNode == nil {
|
||||
let multiplexedNode = MultiplexedVideoNode(account: account)
|
||||
self.multiplexedNode = multiplexedNode
|
||||
if let validLayout = self.validLayout {
|
||||
multiplexedNode.frame = CGRect(origin: CGPoint(), size: validLayout)
|
||||
}
|
||||
|
||||
self.view.addSubview(multiplexedNode)
|
||||
let initialOrder = Atomic<[MediaId]?>(value: nil)
|
||||
let gifs = self.account.postbox.combinedView(keys: [.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)])
|
||||
|> map { view -> [TelegramMediaFile] in
|
||||
var recentGifs: OrderedItemListView?
|
||||
if let orderedView = view.views[.orderedItemList(id: Namespaces.OrderedItemList.CloudRecentGifs)] {
|
||||
recentGifs = orderedView as? OrderedItemListView
|
||||
}
|
||||
if let recentGifs = recentGifs {
|
||||
return recentGifs.items.map { ($0.contents as! RecentMediaItem).media as! TelegramMediaFile }
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
self.disposable.set((gifs |> deliverOnMainQueue).start(next: { [weak self] gifs in
|
||||
if let strongSelf = self {
|
||||
strongSelf.multiplexedNode?.files = gifs
|
||||
}
|
||||
}))
|
||||
|
||||
multiplexedNode.fileSelected = { [weak self] file in
|
||||
self?.controllerInteraction.sendGif(file)
|
||||
}
|
||||
multiplexedNode.fileLongPressed = { [weak self] file in
|
||||
if let strongSelf = self, let multiplexedNode = strongSelf.multiplexedNode, let itemFrame = multiplexedNode.frameForItem(file.fileId) {
|
||||
let presentationData = strongSelf.account.telegramApplicationContext.currentPresentationData.with { $0 }
|
||||
let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(presentationData.strings.Common_Delete), action: {
|
||||
if let strongSelf = self {
|
||||
let _ = removeSavedGif(postbox: strongSelf.account.postbox, mediaId: file.fileId).start()
|
||||
}
|
||||
})])
|
||||
strongSelf.controllerInteraction.presentController(contextMenuController, ContextMenuControllerPresentationArguments(sourceNodeAndRect: {
|
||||
if let strongSelf = self, let multiplexedNode = strongSelf.multiplexedNode {
|
||||
return (strongSelf, multiplexedNode.convert(itemFrame, to: strongSelf.view).insetBy(dx: -2.0, dy: -2.0).offsetBy(dx: multiplexedNode.frame.minX, dy: multiplexedNode.frame.minY))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user