Minor refactoring

pull/404/head
Niels Andriesse 4 years ago
parent 54684ba565
commit 33a16df602

@ -201,14 +201,15 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
private func showMainContent() { private func showMainContent() {
let threadPickerVC = ThreadPickerVC() let threadPickerVC = ThreadPickerVC()
threadPickerVC.shareVC = self threadPickerVC.shareDelegate = self
setViewControllers([ threadPickerVC ], animated: false) setViewControllers([ threadPickerVC ], animated: false)
showLoader()
let promise = buildAttachments() let promise = buildAttachments()
promise.done { [weak self] _ in ModalActivityIndicatorViewController.present(fromViewController: self, canCancel: false) { activityIndicator in
self?.hideLoader() promise.done { _ in
}.catch { [weak self] _ in activityIndicator.dismiss { }
self?.hideLoader() }.catch { _ in
activityIndicator.dismiss { }
}
} }
ShareVC.attachmentPrepPromise = promise ShareVC.attachmentPrepPromise = promise
} }
@ -229,14 +230,6 @@ final class ShareVC : UINavigationController, ShareViewDelegate, AppModeManagerD
extensionContext!.cancelRequest(withError: error) extensionContext!.cancelRequest(withError: error)
} }
func showLoader() {
}
func hideLoader() {
}
// MARK: Attachment Prep // MARK: Attachment Prep
private class func itemMatchesSpecificUtiType(itemProvider: NSItemProvider, utiType: String) -> Bool { private class func itemMatchesSpecificUtiType(itemProvider: NSItemProvider, utiType: String) -> Bool {
// URLs, contacts and other special items have to be detected separately. // URLs, contacts and other special items have to be detected separately.

@ -4,7 +4,7 @@ final class ThreadPickerVC : UIViewController, UITableViewDataSource, UITableVie
private var threads: YapDatabaseViewMappings! private var threads: YapDatabaseViewMappings!
private var threadViewModelCache: [String:ThreadViewModel] = [:] // Thread ID to ThreadViewModel private var threadViewModelCache: [String:ThreadViewModel] = [:] // Thread ID to ThreadViewModel
private var selectedThread: TSThread? private var selectedThread: TSThread?
var shareVC: ShareVC? var shareDelegate: ShareViewDelegate?
private var threadCount: UInt { private var threadCount: UInt {
threads.numberOfItems(inGroup: TSInboxGroup) threads.numberOfItems(inGroup: TSInboxGroup)
@ -100,7 +100,6 @@ final class ThreadPickerVC : UIViewController, UITableViewDataSource, UITableVie
} }
func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didApproveAttachments attachments: [SignalAttachment], messageText: String?) { func attachmentApproval(_ attachmentApproval: AttachmentApprovalViewController, didApproveAttachments attachments: [SignalAttachment], messageText: String?) {
shareVC?.showLoader()
let message = VisibleMessage() let message = VisibleMessage()
message.sentTimestamp = NSDate.millisecondTimestamp() message.sentTimestamp = NSDate.millisecondTimestamp()
message.text = messageText message.text = messageText
@ -108,17 +107,21 @@ final class ThreadPickerVC : UIViewController, UITableViewDataSource, UITableVie
Storage.write { transaction in Storage.write { transaction in
tsMessage.save(with: transaction) tsMessage.save(with: transaction)
} }
Storage.write { transaction in // DispatchQueue.main.async {
MessageSender.sendNonDurably(message, with: attachments, in: self.selectedThread!, using: transaction).done { [weak self] _ in // ModalActivityIndicatorViewController.present(fromViewController: self.navigationController!, canCancel: false) { activityIndicator in
guard let self = self else { return } Storage.write { transaction in
self.shareVC?.hideLoader() MessageSender.sendNonDurably(message, with: attachments, in: self.selectedThread!, using: transaction).done { [weak self] _ in
self.shareVC?.shareViewWasCompleted() guard let self = self else { return }
}.catch { [weak self] error in // activityIndicator.dismiss { }
guard let self = self else { return } self.shareDelegate?.shareViewWasCompleted()
self.shareVC?.hideLoader() }.catch { [weak self] error in
self.shareVC?.shareViewFailed(error: error) guard let self = self else { return }
} // activityIndicator.dismiss { }
} self.shareDelegate?.shareViewFailed(error: error)
}
}
// }
// }
} }
func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) { func attachmentApprovalDidCancel(_ attachmentApproval: AttachmentApprovalViewController) {

Loading…
Cancel
Save