|
@@ -5,10 +5,8 @@ import AVFoundation
|
|
|
import DcCore
|
|
|
import SDWebImage
|
|
|
|
|
|
-class ChatViewController: UITableViewController {
|
|
|
+class ChatViewController: UITableViewController, UITableViewDropDelegate {
|
|
|
var dcContext: DcContext
|
|
|
- let outgoingAvatarOverlap: CGFloat = 17.5
|
|
|
- let loadCount = 30
|
|
|
let chatId: Int
|
|
|
var messageIds: [Int] = []
|
|
|
|
|
@@ -30,6 +28,12 @@ class ChatViewController: UITableViewController {
|
|
|
return draft
|
|
|
}()
|
|
|
|
|
|
+ private lazy var dropInteraction: ChatDropInteraction = {
|
|
|
+ let dropInteraction = ChatDropInteraction()
|
|
|
+ dropInteraction.delegate = self
|
|
|
+ return dropInteraction
|
|
|
+ }()
|
|
|
+
|
|
|
// search related
|
|
|
private var activateSearch: Bool = false
|
|
|
private var searchMessageIds: [Int] = []
|
|
@@ -393,6 +397,8 @@ class ChatViewController: UITableViewController {
|
|
|
messageInputBar.inputTextView.text = draft.text
|
|
|
configureDraftArea(draft: draft, animated: false)
|
|
|
tableView.allowsMultipleSelectionDuringEditing = true
|
|
|
+ tableView.dragInteractionEnabled = true
|
|
|
+ tableView.dropDelegate = self
|
|
|
}
|
|
|
|
|
|
private func getTopInsetHeight() -> CGFloat {
|
|
@@ -1267,6 +1273,7 @@ class ChatViewController: UITableViewController {
|
|
|
messageInputBar.inputTextView.delegate = self
|
|
|
messageInputBar.inputTextView.imagePasteDelegate = self
|
|
|
messageInputBar.onScrollDownButtonPressed = scrollToBottom
|
|
|
+ messageInputBar.inputTextView.setDropInteractionDelegate(delegate: self)
|
|
|
}
|
|
|
|
|
|
private func evaluateInputBar(draft: DraftModel) {
|
|
@@ -1686,9 +1693,13 @@ class ChatViewController: UITableViewController {
|
|
|
|
|
|
private func stageDocument(url: NSURL) {
|
|
|
keepKeyboard = true
|
|
|
- self.draft.setAttachment(viewType: url.pathExtension == "xdc" ? DC_MSG_WEBXDC : DC_MSG_FILE, path: url.relativePath)
|
|
|
- self.configureDraftArea(draft: self.draft)
|
|
|
- self.focusInputTextView()
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
|
+ guard let self = self else { return }
|
|
|
+ self.draft.setAttachment(viewType: url.pathExtension == "xdc" ? DC_MSG_WEBXDC : DC_MSG_FILE, path: url.relativePath)
|
|
|
+ self.configureDraftArea(draft: self.draft)
|
|
|
+ self.focusInputTextView()
|
|
|
+ FileHelper.deleteFile(atPath: url.relativePath)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private func stageVideo(url: NSURL) {
|
|
@@ -1698,6 +1709,7 @@ class ChatViewController: UITableViewController {
|
|
|
self.draft.setAttachment(viewType: DC_MSG_VIDEO, path: url.relativePath)
|
|
|
self.configureDraftArea(draft: self.draft)
|
|
|
self.focusInputTextView()
|
|
|
+ FileHelper.deleteFile(atPath: url.relativePath)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1722,7 +1734,7 @@ class ChatViewController: UITableViewController {
|
|
|
}
|
|
|
self.configureDraftArea(draft: self.draft)
|
|
|
self.focusInputTextView()
|
|
|
- ImageFormat.deleteImage(atPath: pathInCachesDir)
|
|
|
+ FileHelper.deleteFile(atPath: pathInCachesDir)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1733,7 +1745,7 @@ class ChatViewController: UITableViewController {
|
|
|
guard let self = self else { return }
|
|
|
if let path = ImageFormat.saveImage(image: image, directory: .cachesDirectory) {
|
|
|
self.sendAttachmentMessage(viewType: DC_MSG_IMAGE, filePath: path, message: message)
|
|
|
- ImageFormat.deleteImage(atPath: path)
|
|
|
+ FileHelper.deleteFile(atPath: path)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1743,7 +1755,7 @@ class ChatViewController: UITableViewController {
|
|
|
guard let self = self else { return }
|
|
|
if let path = ImageFormat.saveImage(image: image, directory: .cachesDirectory) {
|
|
|
self.sendAttachmentMessage(viewType: DC_MSG_STICKER, filePath: path, message: nil)
|
|
|
- ImageFormat.deleteImage(atPath: path)
|
|
|
+ FileHelper.deleteFile(atPath: path)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1795,6 +1807,21 @@ class ChatViewController: UITableViewController {
|
|
|
return !isHidden
|
|
|
}
|
|
|
|
|
|
+ @objc(tableView:canHandleDropSession:)
|
|
|
+ func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
|
|
|
+ return self.dropInteraction.dropInteraction(canHandle: session)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc
|
|
|
+ func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
|
|
|
+ return UITableViewDropProposal(operation: .copy)
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc(tableView:performDropWithCoordinator:)
|
|
|
+ func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
|
|
|
+ return self.dropInteraction.dropInteraction(performDrop: coordinator.session)
|
|
|
+ }
|
|
|
+
|
|
|
override func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
|
|
|
return !tableView.isEditing && contextMenu.canPerformAction(action: action)
|
|
|
}
|
|
@@ -2437,3 +2464,27 @@ extension ChatViewController: WebxdcSelectorDelegate {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension ChatViewController: ChatDropInteractionDelegate {
|
|
|
+ func onImageDragAndDropped(image: UIImage) {
|
|
|
+ stageImage(image)
|
|
|
+ }
|
|
|
+
|
|
|
+ func onVideoDragAndDropped(url: NSURL) {
|
|
|
+ stageVideo(url: url)
|
|
|
+ }
|
|
|
+
|
|
|
+ func onFileDragAndDropped(url: NSURL) {
|
|
|
+ stageDocument(url: url)
|
|
|
+ }
|
|
|
+
|
|
|
+ func onTextDragAndDropped(text: String) {
|
|
|
+ if messageInputBar.inputTextView.text.isEmpty {
|
|
|
+ messageInputBar.inputTextView.text = text
|
|
|
+ } else {
|
|
|
+ var updatedText = messageInputBar.inputTextView.text
|
|
|
+ updatedText?.append(" \(text) ")
|
|
|
+ messageInputBar.inputTextView.text = updatedText
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|