Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 11
ability to send encrypted attachments#505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e907d489f9383ff4f58d8fa3bda217227340b3ba8f10e8ca735efee79af65f9f40d984cac7290File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -34,6 +34,8 @@ final class ComposeViewController: TableNodeViewController { | ||
| private let notificationCenter: NotificationCenter | ||
| private let decorator: ComposeViewDecorator | ||
| private let contactsService: ContactsServiceType | ||
| private let filesManager: FilesManagerType | ||
| private let photosManager: PhotosManagerType | ||
| private let searchThrottler = Throttler(seconds: 1) | ||
| private let cloudContactProvider: CloudContactsProvider | ||
| @@ -55,7 +57,9 @@ final class ComposeViewController: TableNodeViewController { | ||
| cloudContactProvider: CloudContactsProvider = UserContactsProvider(), | ||
| userDefaults: UserDefaults = .standard, | ||
| contactsService: ContactsServiceType = ContactsService(), | ||
| composeMessageService: ComposeMessageService = ComposeMessageService() | ||
| composeMessageService: ComposeMessageService = ComposeMessageService(), | ||
| filesManager: FilesManagerType = FilesManager(), | ||
| photosManager: PhotosManagerType = PhotosManager() | ||
| ) { | ||
| self.email = email | ||
| self.notificationCenter = notificationCenter | ||
| @@ -65,6 +69,8 @@ final class ComposeViewController: TableNodeViewController { | ||
| self.userDefaults = userDefaults | ||
| self.contactsService = contactsService | ||
| self.composeMessageService = composeMessageService | ||
| self.filesManager = filesManager | ||
| self.photosManager = photosManager | ||
| self.contextToSend.subject = input.subject | ||
| super.init(node: TableNode()) | ||
| } | ||
| @@ -184,8 +190,7 @@ extension ComposeViewController { | ||
| } | ||
| @objc private func handleAttachTap() { | ||
| #warning("ToDo") | ||
| showToast("Attachments not implemented yet") | ||
| openAttachmentsInputSourcesSheet() | ||
| } | ||
| @objc private func handleSendTap() { | ||
| @@ -198,15 +203,13 @@ extension ComposeViewController { | ||
| extension ComposeViewController { | ||
| private func sendMessage() { | ||
| view.endEditing(true) | ||
| showSpinner("sending_title".localized) | ||
| navigationItem.rightBarButtonItem?.isEnabled = false | ||
| composeMessageService.validateMessage( | ||
| input: input, | ||
| contextToSend: contextToSend, | ||
| email: email, | ||
| atts: [] | ||
| email: email | ||
| ) | ||
| .publisher | ||
| .flatMap(composeMessageService.encryptAndSend) | ||
| @@ -243,7 +246,7 @@ extension ComposeViewController { | ||
| extension ComposeViewController: ASTableDelegate, ASTableDataSource { | ||
| func numberOfSections(in _: ASTableNode) -> Int { | ||
| 2 | ||
| 3 | ||
| } | ||
| func tableNode(_: ASTableNode, numberOfRowsInSection section: Int) -> Int { | ||
| @@ -252,6 +255,8 @@ extension ComposeViewController: ASTableDelegate, ASTableDataSource { | ||
| return RecipientParts.allCases.count | ||
| case (.main, 1): | ||
| return ComposeParts.allCases.count | ||
| case (.main, 2): | ||
| return contextToSend.attachments.count | ||
| case (.searchEmails, 0): | ||
| return RecipientParts.allCases.count | ||
| case let (.searchEmails(emails), 1): | ||
| @@ -285,6 +290,11 @@ extension ComposeViewController: ASTableDelegate, ASTableDataSource { | ||
| case .text: return self.textNode(with: nodeHeight) | ||
| case .subjectDivider: return DividerCellNode() | ||
| } | ||
| case (.main, 2): | ||
| guard !self.contextToSend.attachments.isEmpty else { | ||
| return ASCellNode() | ||
| } | ||
| return self.attachmentNode(for: indexPath.row) | ||
| case let (.searchEmails(emails), 1): | ||
| return InfoCellNode(input: self.decorator.styledRecipientInfo(with: emails[indexPath.row])) | ||
| default: | ||
| @@ -328,21 +338,17 @@ extension ComposeViewController { | ||
| } | ||
| private func textNode(with nodeHeight: CGFloat) -> ASCellNode { | ||
| let textFieldHeight = decorator.styledTextFieldInput(with: "").height | ||
| let dividerHeight: CGFloat = 1 | ||
| let preferredHeight = nodeHeight - 2 * (textFieldHeight + dividerHeight) | ||
| return TextViewCellNode( | ||
| decorator.styledTextViewInput(with: preferredHeight) | ||
| ) { [weak self] event in | ||
| guard case let .didEndEditing(text) = event else { return } | ||
| self?.contextToSend.message = text?.string | ||
| } | ||
| .then { | ||
| guard self.input.isReply else { return } | ||
| $0.textView.attributedText = self.decorator.styledReplyQuote(with: self.input) | ||
| $0.becomeFirstResponder() | ||
| } | ||
| decorator.styledTextViewInput(with: 40), | ||
| action: { [weak self] event in | ||
| guard case let .didEndEditing(text) = event else { return } | ||
| self?.contextToSend.message = text?.string | ||
| }) | ||
| .then { | ||
| guard self.input.isReply else { return } | ||
| $0.textView.attributedText = self.decorator.styledReplyQuote(with: self.input) | ||
| $0.becomeFirstResponder() | ||
| } | ||
| } | ||
| private func recipientsNode() -> RecipientEmailsCellNode { | ||
| @@ -357,7 +363,7 @@ extension ComposeViewController { | ||
| private func recipientInput() -> TextFieldCellNode { | ||
| TextFieldCellNode( | ||
| input: decorator.styledTextFieldInput(with: "compose_recipient".localized) | ||
| input: decorator.styledTextFieldInput(with: "compose_recipient".localized, keyboardType: .emailAddress) | ||
| ) { [weak self] action in | ||
| self?.handleTextFieldAction(with: action) | ||
| } | ||
| @@ -375,6 +381,14 @@ extension ComposeViewController { | ||
| } | ||
| } | ||
| } | ||
| private func attachmentNode(for index: Int) -> ASCellNode { | ||
| AttachmentNode( | ||
| input: .init( | ||
| composeAttachment: contextToSend.attachments[index] | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| // MARK: - Recipients Input | ||
| @@ -633,6 +647,132 @@ extension ComposeViewController { | ||
| } | ||
| } | ||
| // MARK: - UIDocumentPickerDelegate | ||
| extension ComposeViewController: UIDocumentPickerDelegate { | ||
| func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { | ||
| guard let fileUrl = urls.first, | ||
| let attachment = ComposeMessageAttachment(fileURL: fileUrl) | ||
| else { | ||
| showAlert(message: "files_picking_files_error_message".localized) | ||
| return | ||
| } | ||
| appendAttachmentIfAllowed(attachment) | ||
| node.reloadSections(IndexSet(integer: 2), with: .automatic) | ||
| } | ||
| } | ||
| // MARK: - UIImagePickerControllerDelegate & UINavigationControllerDelegate | ||
| extension ComposeViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | ||
| func imagePickerController( | ||
| _ picker: UIImagePickerController, | ||
| didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any] | ||
| ) { | ||
| picker.dismiss(animated: true, completion: nil) | ||
| let attachment: ComposeMessageAttachment? | ||
| switch picker.sourceType { | ||
| case .camera: | ||
| attachment = ComposeMessageAttachment(cameraSourceMediaInfo: info) | ||
| case .photoLibrary: | ||
| attachment = ComposeMessageAttachment(librarySourceMediaInfo: info) | ||
| default: fatalError("No other image picker's sources should be used") | ||
| } | ||
| guard let attachment = attachment else { | ||
| showAlert(message: "files_picking_photos_error_message".localized) | ||
| return | ||
| } | ||
| appendAttachmentIfAllowed(attachment) | ||
| node.reloadSections(IndexSet(integer: 2), with: .automatic) | ||
| } | ||
| private func appendAttachmentIfAllowed(_ attachment: ComposeMessageAttachment) { | ||
| let totalSize = contextToSend.attachments.reduce(0, { $0 + $1.size }) | ||
| if totalSize > GeneralConstants.Global.attachmentSizeLimit { | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be | ||
| showToast("files_picking_size_error_message".localized) | ||
| } else { | ||
| contextToSend.attachments.append(attachment) | ||
| } | ||
| } | ||
| } | ||
| // MARK: - Attachments sheet handling | ||
| extension ComposeViewController { | ||
| private func openAttachmentsInputSourcesSheet() { | ||
| let alert = UIAlertController( | ||
| title: "files_picking_select_input_source_title".localized, | ||
| message: nil, preferredStyle: .actionSheet | ||
| ) | ||
| alert.addAction( | ||
| UIAlertAction( | ||
| title: "files_picking_camera_input_source".localized, | ||
| style: .default, | ||
| handler: { [weak self] _ in | ||
| guard let self = self else { return } | ||
| self.photosManager.selectPhoto(source: .camera, from: self) | ||
| .sinkFuture( | ||
| receiveValue: {}, | ||
| receiveError: { _ in | ||
| self.showNoAccessToPhotosAlert() | ||
| } | ||
| ) | ||
| .store(in: &self.cancellable) | ||
| } | ||
| ) | ||
| ) | ||
| alert.addAction( | ||
| UIAlertAction( | ||
| title: "files_picking_photo_library_source".localized, | ||
| style: .default, | ||
| handler: { [weak self] _ in | ||
| guard let self = self else { return } | ||
| self.photosManager.selectPhoto(source: .photoLibrary, from: self) | ||
| .sinkFuture( | ||
| receiveValue: {}, | ||
| receiveError: { _ in | ||
| self.showNoAccessToPhotosAlert() | ||
| } | ||
| ) | ||
| .store(in: &self.cancellable) | ||
| } | ||
| ) | ||
| ) | ||
| alert.addAction( | ||
| UIAlertAction( | ||
| title: "files_picking_files_source".localized, | ||
| style: .default, | ||
| handler: { [weak self] _ in | ||
| guard let self = self else { return } | ||
| self.filesManager.selectFromFilesApp(from: self) | ||
| } | ||
| ) | ||
| ) | ||
| alert.addAction(UIAlertAction(title: "cancel".localized, style: .cancel)) | ||
| present(alert, animated: true, completion: nil) | ||
| } | ||
| private func showNoAccessToPhotosAlert() { | ||
| let alert = UIAlertController( | ||
| title: "files_picking_no_library_access_error_title".localized, | ||
| message: "files_picking_no_library_access_error_message".localized, | ||
| preferredStyle: .alert | ||
| ) | ||
| let okAction = UIAlertAction( | ||
| title: "OK", | ||
| style: .cancel | ||
| ) { _ in } | ||
| let settingsAction = UIAlertAction( | ||
| title: "setttings".localized, | ||
| style: .default | ||
| ) { _ in | ||
| UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) | ||
| } | ||
| alert.addAction(okAction) | ||
| alert.addAction(settingsAction) | ||
| present(alert, animated: true, completion: nil) | ||
| } | ||
| } | ||
| // temporary disable search contacts | ||
| // https://github.com/FlowCrypt/flowcrypt-ios/issues/217 | ||
| extension ComposeViewController { | ||
| @@ -650,7 +790,7 @@ extension ComposeViewController { | ||
| style: .default | ||
| ) { _ in } | ||
| let cancelAction = UIAlertAction( | ||
| title: "Cancel", | ||
| title: "cancel".localized, | ||
| style: .destructive | ||
| ) { _ in } | ||
| alert.addAction(okAction) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the whole
tableNodeshould be in some sort of decorator class? It looks very UI-heavy with not much business logic. What do you think @Kharchevskyi ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, then that would apply to the whole
extension ComposeViewController: ASTableDelegate, ASTableDataSource {sectionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we may create DataSource entity for this screen, @Kharchevskyi let's discuss that when it's convenient