Implement basic sending logic

pull/404/head
Niels Andriesse 4 years ago
parent e09b0ebd3f
commit 0cbcf0b169

@ -4,6 +4,7 @@ import SessionUIKit
final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerDelegate {
private var areVersionMigrationsComplete = false
public static var attachmentPrepPromise: Promise<[SignalAttachment]>?
// MARK: Error
enum ShareViewControllerError: Error {
@ -201,7 +202,7 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
private func showMainContent() {
let threadPickerVC = ThreadPickerVC()
setViewControllers([ threadPickerVC ], animated: false)
buildAttachments().retainUntilComplete()
ShareVC.attachmentPrepPromise = buildAttachments()
}
func shareViewWasUnlocked() {
@ -546,29 +547,7 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
guard !SignalAttachment.isInvalidVideo(dataSource: dataSource, dataUTI: specificUTIType) else {
// This can happen, e.g. when sharing a quicktime-video from iCloud drive.
let (promise, exportSession) = SignalAttachment.compressVideoAsMp4(dataSource: dataSource, dataUTI: specificUTIType)
/*
// TODO: How can we move waiting for this export to the end of the share flow rather than having to do it up front?
// Ideally we'd be able to start it here, and not block the UI on conversion unless there's still work to be done
// when the user hits "send".
if let exportSession = exportSession {
let progressPoller = ProgressPoller(timeInterval: 0.1, ratioCompleteBlock: { return exportSession.progress })
self.progressPoller = progressPoller
progressPoller.startPolling()
guard let loadViewController = self.loadViewController else {
owsFailDebug("load view controller was unexpectedly nil")
return promise
}
DispatchQueue.main.async {
loadViewController.progress = progressPoller.progress
}
}
*/
let (promise, _) = SignalAttachment.compressVideoAsMp4(dataSource: dataSource, dataUTI: specificUTIType)
return promise
}

@ -1,8 +1,9 @@
import SessionUIKit
final class ThreadPickerVC : UIViewController, UITableViewDataSource {
final class ThreadPickerVC : UIViewController, UITableViewDataSource, UITableViewDelegate, AttachmentApprovalViewControllerDelegate {
private var threads: YapDatabaseViewMappings!
private var threadViewModelCache: [String:ThreadViewModel] = [:] // Thread ID to ThreadViewModel
private var selectedThread: TSThread?
private var threadCount: UInt {
threads.numberOfItems(inGroup: TSInboxGroup)
@ -53,6 +54,7 @@ final class ThreadPickerVC : UIViewController, UITableViewDataSource {
navigationItem.titleView = titleLabel
// Table view
tableView.dataSource = self
tableView.delegate = self
view.addSubview(tableView)
tableView.pin(to: view)
view.addSubview(fadeView)
@ -89,9 +91,32 @@ final class ThreadPickerVC : UIViewController, UITableViewDataSource {
// MARK: Interaction
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let thread = self.thread(at: indexPath.row) else { return }
// TODO: Send the attachment
guard let thread = self.thread(at: indexPath.row), let attachments = ShareVC.attachmentPrepPromise?.value else { return }
self.selectedThread = thread
tableView.deselectRow(at: indexPath, animated: true)
let approvalVC = AttachmentApprovalViewController.wrappedInNavController(attachments: attachments, approvalDelegate: self)
navigationController!.present(approvalVC, animated: true, completion: nil)
}
func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didApproveAttachments attachments: [SignalAttachment], messageText: String?) {
let message = VisibleMessage()
message.sentTimestamp = NSDate.millisecondTimestamp()
message.text = messageText
let tsMessage = TSOutgoingMessage.from(message, associatedWith: selectedThread!)
Storage.write { transaction in
tsMessage.save(with: transaction)
}
Storage.write { transaction in
MessageSender.sendNonDurably(message, with: attachments, in: self.selectedThread!, using: transaction).retainUntilComplete()
}
}
func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) {
}
func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didChangeMessageText newMessageText: String?) {
}
// MARK: Convenience

Loading…
Cancel
Save