-
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
Merged
tomholub
merged 11 commits into
master
from
feature/issue-196-ability-to-send-attachment
Sep 27, 2021
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e907d48
Added ability to size textview to its content;
9f9383f
Added ability to compose message with encrypted attachmen(Photo and a…
f4f58d8
Resolving mime types for files;
fa3bda2
Merge branch 'master' into feature/issue-196-ability-to-send-attachment
ekievsky 1722734
Fixed spaces;
0b3ba8f
Merge branch 'feature/issue-196-ability-to-send-attachment' of github…
10e8ca7
Merge branch 'master' into feature/issue-196-ability-to-send-attachment
tomholub 35efee7
Merge branch 'master' into feature/issue-196-ability-to-send-attachment
tomholub 9af65f9
Fixed tests and PR comments;
f40d984
Merge branch 'feature/issue-196-ability-to-send-attachment' of github…
cac7290
Merge branch 'master' into feature/issue-196-ability-to-send-attachment
tomholub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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