From 661a61da92054449c5f13f1c6ab7b04337f03326 Mon Sep 17 00:00:00 2001 From: QSD_e Date: Wed, 28 Apr 2021 10:35:56 +0200 Subject: [PATCH 1/4] issue #193 add attachment nodes --- FlowCrypt.xcodeproj/project.pbxproj | 6 +- .../Msg/MessageViewController.swift | 11 ++- FlowCrypt/Core/CoreTypes.swift | 2 +- FlowCryptUI/Nodes/AttachmentNode.swift | 99 +++++++++++++++++++ 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 FlowCryptUI/Nodes/AttachmentNode.swift diff --git a/FlowCrypt.xcodeproj/project.pbxproj b/FlowCrypt.xcodeproj/project.pbxproj index 25433beaf..a69e4411d 100644 --- a/FlowCrypt.xcodeproj/project.pbxproj +++ b/FlowCrypt.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 32DCAF683D87EA6221F71335 /* SequenceExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCA058652FD4616FB04FB6 /* SequenceExtensions.swift */; }; 32DCAF95A6A329C3136B1C8E /* Imap+msg.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCA55C094E9745AA1FD210 /* Imap+msg.swift */; }; 32DCAF9DA9EC47798DF8BB73 /* SignInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32DCA9701B2D5052225A0414 /* SignInViewController.swift */; }; + 50531BE42629B9A80039BAE9 /* AttachmentNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50531BE32629B9A80039BAE9 /* AttachmentNode.swift */; }; 5A39F42D239EC321001F4607 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A39F42C239EC321001F4607 /* SettingsViewController.swift */; }; 5A39F430239EC396001F4607 /* SettingsViewDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A39F42F239EC396001F4607 /* SettingsViewDecorator.swift */; }; 5A39F437239ECC23001F4607 /* KeySettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A39F436239ECC23001F4607 /* KeySettingsViewController.swift */; }; @@ -132,7 +133,6 @@ 9FE1B3802563F85400D6D086 /* MessagesListProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B37F2563F85400D6D086 /* MessagesListProvider.swift */; }; 9FE1B3942563F98600D6D086 /* Imap+MessagesList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B3932563F98600D6D086 /* Imap+MessagesList.swift */; }; 9FE1B3A02565B0CE00D6D086 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE1B39F2565B0CD00D6D086 /* Message.swift */; }; - 9FE233D825712E51003D7C7E /* test-ci-secrets.json in Resources */ = {isa = PBXBuildFile; fileRef = 9FE233D725712E51003D7C7E /* test-ci-secrets.json */; }; 9FE743072347AA54005E2DBB /* MainNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE743062347AA54005E2DBB /* MainNavigationController.swift */; }; 9FEED1D2230DAD1E00700F8E /* InboxViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEED1D1230DAD1E00700F8E /* InboxViewModel.swift */; }; 9FF0670825520CF800FCC9E6 /* GmailService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF0670725520CF800FCC9E6 /* GmailService.swift */; }; @@ -368,6 +368,7 @@ 411CEC75050F852F172CD687 /* Pods-FlowCryptTests.testflight.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlowCryptTests.testflight.xcconfig"; path = "Target Support Files/Pods-FlowCryptTests/Pods-FlowCryptTests.testflight.xcconfig"; sourceTree = ""; }; 44D0BF0D60EF854CEC17561C /* Pods-FlowCryptUIApplication.testflight.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlowCryptUIApplication.testflight.xcconfig"; path = "Target Support Files/Pods-FlowCryptUIApplication/Pods-FlowCryptUIApplication.testflight.xcconfig"; sourceTree = ""; }; 4A76C3D4559C9F415D392A62 /* Pods-FlowCryptTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlowCryptTests.debug.xcconfig"; path = "Target Support Files/Pods-FlowCryptTests/Pods-FlowCryptTests.debug.xcconfig"; sourceTree = ""; }; + 50531BE32629B9A80039BAE9 /* AttachmentNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentNode.swift; sourceTree = ""; }; 567BA6739257FE0D2924D82C /* Pods_FlowCryptUIApplication.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlowCryptUIApplication.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5A39F42C239EC321001F4607 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 5A39F42F239EC396001F4607 /* SettingsViewDecorator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewDecorator.swift; sourceTree = ""; }; @@ -1578,6 +1579,7 @@ 9F4453BF236B894D005D7D05 /* TableNode.swift */, 9F4453C1236B9273005D7D05 /* TextFieldNode.swift */, D24FAFAA2520BFAE00BF46C5 /* CheckBoxNode.swift */, + 50531BE32629B9A80039BAE9 /* AttachmentNode.swift */, ); path = Nodes; sourceTree = ""; @@ -1854,7 +1856,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9FE233D825712E51003D7C7E /* test-ci-secrets.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2406,6 +2407,7 @@ D28655912423B4580066F52E /* HeaderNode.swift in Sources */, D271774C242558DA00BDA9A9 /* MessageTextSubjectNode.swift in Sources */, D27177502425659F00BDA9A9 /* SettingsCellNode.swift in Sources */, + 50531BE42629B9A80039BAE9 /* AttachmentNode.swift in Sources */, D2CDC3D824047066002B045F /* RecipientEmailNode.swift in Sources */, D2717753242568A600BDA9A9 /* NavigationBarItemsView.swift in Sources */, D211CE7023FC35AC00D1CE38 /* TableNode.swift in Sources */, diff --git a/FlowCrypt/Controllers/Msg/MessageViewController.swift b/FlowCrypt/Controllers/Msg/MessageViewController.swift index e073f26d5..34b33813a 100644 --- a/FlowCrypt/Controllers/Msg/MessageViewController.swift +++ b/FlowCrypt/Controllers/Msg/MessageViewController.swift @@ -14,7 +14,7 @@ final class MessageViewController: TableNodeViewController { } enum Parts: Int, CaseIterable { - case sender, subject, text + case sender, subject, text, attachment var indexPath: IndexPath { IndexPath(row: rawValue, section: 0) @@ -171,6 +171,10 @@ extension MessageViewController { ) let decryptErrBlocks = decrypted.blocks.filter { $0.decryptErr != nil } + decrypted.blocks.forEach { block in + // + } + let message: NSAttributedString if let decryptErrBlock = decryptErrBlocks.first { let rawMsg = decryptErrBlock.content @@ -366,6 +370,9 @@ extension MessageViewController: ASTableDelegate, ASTableDataSource { date: input?.objMessage.date ) + let input = AttachmentsNode.Input.init(name: "Attachment 1", size: "100 MB") + let input2 = AttachmentsNode.Input.init(name: "Attachment 2", size: "16 MB") + return { [weak self] in guard let self = self, let part = Parts(rawValue: indexPath.row) else { return ASCellNode() } switch part { @@ -377,6 +384,8 @@ extension MessageViewController: ASTableDelegate, ASTableDataSource { return MessageSubjectNode(subject, time: time) case .text: return MessageTextSubjectNode(self.message) + case .attachment: + return AttachmentsNode.init(input: [input, input2]) } } } diff --git a/FlowCrypt/Core/CoreTypes.swift b/FlowCrypt/Core/CoreTypes.swift index 5b3e7c7db..90959d11f 100644 --- a/FlowCrypt/Core/CoreTypes.swift +++ b/FlowCrypt/Core/CoreTypes.swift @@ -19,7 +19,7 @@ struct CoreRes { let text: String } - struct ParseDecryptMsg { + struct ParseDecryptMsg: Decodable { let replyType: ReplyType let text: String let blocks: [MsgBlock] diff --git a/FlowCryptUI/Nodes/AttachmentNode.swift b/FlowCryptUI/Nodes/AttachmentNode.swift new file mode 100644 index 000000000..b5e318255 --- /dev/null +++ b/FlowCryptUI/Nodes/AttachmentNode.swift @@ -0,0 +1,99 @@ +// +// AttachmentNode.swift +// FlowCryptUI +// +// Created by QSD BiH on 16. 4. 2021.. +// Copyright © 2021 FlowCrypt Limited. All rights reserved. +// + +import AsyncDisplayKit + +public struct Attachment { + var name, size: NSAttributedString +} + +public final class AttachmentsNode: CellNode { + public struct Input { + let name: String + let size: String + + public init( + name: String, + size: String + ) { + self.name = name + self.size = size + } + } + + private var attachmentNodes: [AttachmentNode] = [] + + public init(input: [Input]) { + super.init() + input.forEach { input in + attachmentNodes.append( + AttachmentNode( + input: AttachmentNode.Input(name: input.name, size: input.size) + ) + ) + } + } + + public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec { + return ASInsetLayoutSpec( + insets: UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0), + child: ASStackLayoutSpec( + direction: .vertical, + spacing: 8, + justifyContent: .start, + alignItems: .stretch, + children: attachmentNodes)) + } +} + +public final class AttachmentNode: CellNode { + public struct Input { + var name, size: String + } + + private let titleNode = ASTextNode() + private let subtitleNode = ASTextNode2() + private let imageNode = ASImageNode() + private let buttonNode = ASButtonNode() + private let separatorNode = ASDisplayNode() + + public init(input: Input) { + super.init() + self.borderWidth = 0.5 + self.borderColor = UIColor(named: "red")?.cgColor + + imageNode.image = UIImage(named: "paperclip") + buttonNode.setImage(UIImage(named: "paperclip"), for: .normal) + titleNode.attributedText = NSAttributedString.text(from: input.name, style: .medium(16)) + subtitleNode.attributedText = NSAttributedString.text(from: input.size, style: .medium(12)) + } + + public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec { + let verticalStack = ASStackLayoutSpec.vertical() + verticalStack.spacing = 6 + verticalStack.style.flexShrink = 1.0 + verticalStack.style.flexGrow = 1.0 + separatorNode.style.flexGrow = 1.0 + separatorNode.style.preferredSize.height = 1.0 + + verticalStack.children = [titleNode, subtitleNode] + + let finalSpec = ASStackLayoutSpec( + direction: .horizontal, + spacing: 8, + justifyContent: .start, + alignItems: .center, + children: [imageNode, verticalStack, separatorNode, buttonNode] + ) + + return ASInsetLayoutSpec( + insets: UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16), + child: finalSpec + ) + } +} From d623fd80137492117c28025f29f636268bc3dc79 Mon Sep 17 00:00:00 2001 From: QSD_e Date: Wed, 5 May 2021 20:37:14 +0200 Subject: [PATCH 2/4] Parse decrypted blocks --- .../download.imageset/Contents.json | 21 ++++++ .../download.imageset/Light-M.png | Bin 0 -> 430 bytes .../paperclip.imageset/Contents.json | 12 ++-- .../Msg/MessageViewController.swift | 21 +++--- FlowCrypt/Core/CoreTypes.swift | 2 +- FlowCryptUI/Nodes/AttachmentNode.swift | 61 ++++++++++++------ 6 files changed, 82 insertions(+), 35 deletions(-) create mode 100644 FlowCrypt/Assets.xcassets/download.imageset/Contents.json create mode 100644 FlowCrypt/Assets.xcassets/download.imageset/Light-M.png diff --git a/FlowCrypt/Assets.xcassets/download.imageset/Contents.json b/FlowCrypt/Assets.xcassets/download.imageset/Contents.json new file mode 100644 index 000000000..f612e0ad5 --- /dev/null +++ b/FlowCrypt/Assets.xcassets/download.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Light-M.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/FlowCrypt/Assets.xcassets/download.imageset/Light-M.png b/FlowCrypt/Assets.xcassets/download.imageset/Light-M.png new file mode 100644 index 0000000000000000000000000000000000000000..6a3c3a5ea52ca43a9d1d4405ea649cdb1be6e15c GIT binary patch literal 430 zcmeAS@N?(olHy`uVBq!ia0vp^YCvqv!3HFMt5vlDDb50q$YKTtZeb8+WSBKa0w~B> z9OUlAuP=yz|Q)SsE{6O!=M)5C+o(xt$fPt7yBk=a!p=lfP+RUw~f7hpB~=n z)Y@}c&H3v?p5J?CNj*J0*Y>`;>(7E%W6La#JhLgM6`Xd<@opEvpBQ*VR2Ji5T(W$<+Mb6Mw<&;$UG ChqulE literal 0 HcmV?d00001 diff --git a/FlowCrypt/Assets.xcassets/paperclip.imageset/Contents.json b/FlowCrypt/Assets.xcassets/paperclip.imageset/Contents.json index 5f5e212a9..f977fb7df 100644 --- a/FlowCrypt/Assets.xcassets/paperclip.imageset/Contents.json +++ b/FlowCrypt/Assets.xcassets/paperclip.imageset/Contents.json @@ -1,23 +1,23 @@ { "images" : [ { - "idiom" : "universal", "filename" : "paperclip.png", + "idiom" : "universal", "scale" : "1x" }, { - "idiom" : "universal", "filename" : "paperclip@2x.png", + "idiom" : "universal", "scale" : "2x" }, { - "idiom" : "universal", "filename" : "paperclip@3x.png", + "idiom" : "universal", "scale" : "3x" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/FlowCrypt/Controllers/Msg/MessageViewController.swift b/FlowCrypt/Controllers/Msg/MessageViewController.swift index 34b33813a..c5882c475 100644 --- a/FlowCrypt/Controllers/Msg/MessageViewController.swift +++ b/FlowCrypt/Controllers/Msg/MessageViewController.swift @@ -53,6 +53,7 @@ final class MessageViewController: TableNodeViewController { private let messageProvider: MessageProvider private let messageOperationsProvider: MessageOperationsProvider private var message: NSAttributedString + private var attachments: [Attachment] private let trashFolderProvider: TrashFolderProviderType init( @@ -73,6 +74,7 @@ final class MessageViewController: TableNodeViewController { self.core = core self.trashFolderProvider = trashFolderProvider self.onCompletion = completion + self.attachments = [] self.message = decorator.attributed( text: "loading_title".localized + "...", color: .lightGray @@ -143,7 +145,7 @@ extension MessageViewController { self?.message = try await(self!.fetchMessage()) }.then(on: .main) { [weak self] in self?.hideSpinner() - self?.node.reloadRows(at: [Parts.text.indexPath], with: .fade) + self?.node.reloadRows(at: [Parts.text.indexPath, Parts.attachment.indexPath], with: .fade) self?.asyncMarkAsReadIfNotAlreadyMarked() }.catch(on: .main) { [weak self] error in self?.hideSpinner() @@ -170,10 +172,10 @@ extension MessageViewController { isEmail: true ) let decryptErrBlocks = decrypted.blocks.filter { $0.decryptErr != nil } + let decryptAttBlocks = decrypted.blocks.filter { $0.type == .plainAtt || $0.type == .encryptedAtt || $0.type == .decryptedAtt } - decrypted.blocks.forEach { block in - // - } + let attachments = decryptAttBlocks.map { _ in Attachment(name: "Attachment", size: "10 MB") } + self.attachments = attachments let message: NSAttributedString if let decryptErrBlock = decryptErrBlocks.first { @@ -246,6 +248,10 @@ extension MessageViewController { showToast("Marking as unread will be implemented soon") } + @objc private func handleAttachmentTap() { + showToast("Downloading attachments is not implemented yet") + } + @objc private func handleTrashTap() { showSpinner() @@ -370,9 +376,6 @@ extension MessageViewController: ASTableDelegate, ASTableDataSource { date: input?.objMessage.date ) - let input = AttachmentsNode.Input.init(name: "Attachment 1", size: "100 MB") - let input2 = AttachmentsNode.Input.init(name: "Attachment 2", size: "16 MB") - return { [weak self] in guard let self = self, let part = Parts(rawValue: indexPath.row) else { return ASCellNode() } switch part { @@ -385,7 +388,9 @@ extension MessageViewController: ASTableDelegate, ASTableDataSource { case .text: return MessageTextSubjectNode(self.message) case .attachment: - return AttachmentsNode.init(input: [input, input2]) + return AttachmentsNode(attachments: self.attachments) { [weak self] in + self?.handleAttachmentTap() + } } } } diff --git a/FlowCrypt/Core/CoreTypes.swift b/FlowCrypt/Core/CoreTypes.swift index 90959d11f..5b3e7c7db 100644 --- a/FlowCrypt/Core/CoreTypes.swift +++ b/FlowCrypt/Core/CoreTypes.swift @@ -19,7 +19,7 @@ struct CoreRes { let text: String } - struct ParseDecryptMsg: Decodable { + struct ParseDecryptMsg { let replyType: ReplyType let text: String let blocks: [MsgBlock] diff --git a/FlowCryptUI/Nodes/AttachmentNode.swift b/FlowCryptUI/Nodes/AttachmentNode.swift index b5e318255..76b0dde05 100644 --- a/FlowCryptUI/Nodes/AttachmentNode.swift +++ b/FlowCryptUI/Nodes/AttachmentNode.swift @@ -9,7 +9,15 @@ import AsyncDisplayKit public struct Attachment { - var name, size: NSAttributedString + var name, size: String + + public init( + name: String, + size: String + ) { + self.name = name + self.size = size + } } public final class AttachmentsNode: CellNode { @@ -27,21 +35,21 @@ public final class AttachmentsNode: CellNode { } private var attachmentNodes: [AttachmentNode] = [] - - public init(input: [Input]) { + private var onTap: (() -> Void)? + + public init(attachments: [Attachment], onTap: (() -> Void)?) { super.init() - input.forEach { input in - attachmentNodes.append( - AttachmentNode( - input: AttachmentNode.Input(name: input.name, size: input.size) - ) - ) - } + self.onTap = onTap + attachmentNodes = attachments.map { AttachmentNode(input: AttachmentNode.Input(name: $0.name, size: $0.size), + onTap: { + self.onTap?() + }) + } } public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec { return ASInsetLayoutSpec( - insets: UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0), + insets: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8), child: ASStackLayoutSpec( direction: .vertical, spacing: 8, @@ -62,20 +70,29 @@ public final class AttachmentNode: CellNode { private let buttonNode = ASButtonNode() private let separatorNode = ASDisplayNode() - public init(input: Input) { + private var onTap: (() -> Void)? + + public init(input: Input, onTap: (() -> Void)?) { super.init() - self.borderWidth = 0.5 - self.borderColor = UIColor(named: "red")?.cgColor + self.onTap = onTap + + self.borderWidth = 1.0 + self.cornerRadius = 8.0 + self.borderColor = UIColor.lightGray.cgColor + + imageNode.tintColor = .gray + buttonNode.tintColor = .gray imageNode.image = UIImage(named: "paperclip") - buttonNode.setImage(UIImage(named: "paperclip"), for: .normal) - titleNode.attributedText = NSAttributedString.text(from: input.name, style: .medium(16)) - subtitleNode.attributedText = NSAttributedString.text(from: input.size, style: .medium(12)) + buttonNode.setImage(UIImage(named: "download"), for: .normal) + buttonNode.addTarget(self, action: #selector(tapHandle), forControlEvents: .touchUpInside) + titleNode.attributedText = NSAttributedString.text(from: input.name, style: .regular(18), color: .gray, alignment: .left) + subtitleNode.attributedText = NSAttributedString.text(from: input.size, style: .medium(12), color: .gray, alignment: .left) } public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec { let verticalStack = ASStackLayoutSpec.vertical() - verticalStack.spacing = 6 + verticalStack.spacing = 3 verticalStack.style.flexShrink = 1.0 verticalStack.style.flexGrow = 1.0 separatorNode.style.flexGrow = 1.0 @@ -85,15 +102,19 @@ public final class AttachmentNode: CellNode { let finalSpec = ASStackLayoutSpec( direction: .horizontal, - spacing: 8, + spacing: 10, justifyContent: .start, alignItems: .center, children: [imageNode, verticalStack, separatorNode, buttonNode] ) return ASInsetLayoutSpec( - insets: UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16), + insets: UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20), child: finalSpec ) } + + @objc private func tapHandle() { + onTap?() + } } From ae373d550552e16c6c505e2a8f4d6def9e0835bb Mon Sep 17 00:00:00 2001 From: QSD_e Date: Thu, 6 May 2021 10:52:15 +0200 Subject: [PATCH 3/4] issue #193 Update color for AttachmentNode icons --- FlowCryptUI/Nodes/AttachmentNode.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FlowCryptUI/Nodes/AttachmentNode.swift b/FlowCryptUI/Nodes/AttachmentNode.swift index 76b0dde05..c02c521c8 100644 --- a/FlowCryptUI/Nodes/AttachmentNode.swift +++ b/FlowCryptUI/Nodes/AttachmentNode.swift @@ -36,7 +36,7 @@ public final class AttachmentsNode: CellNode { private var attachmentNodes: [AttachmentNode] = [] private var onTap: (() -> Void)? - + public init(attachments: [Attachment], onTap: (() -> Void)?) { super.init() self.onTap = onTap @@ -83,8 +83,8 @@ public final class AttachmentNode: CellNode { imageNode.tintColor = .gray buttonNode.tintColor = .gray - imageNode.image = UIImage(named: "paperclip") - buttonNode.setImage(UIImage(named: "download"), for: .normal) + imageNode.image = UIImage(named: "paperclip")?.tinted(.gray) + buttonNode.setImage(UIImage(named: "download")?.tinted(.gray), for: .normal) buttonNode.addTarget(self, action: #selector(tapHandle), forControlEvents: .touchUpInside) titleNode.attributedText = NSAttributedString.text(from: input.name, style: .regular(18), color: .gray, alignment: .left) subtitleNode.attributedText = NSAttributedString.text(from: input.size, style: .medium(12), color: .gray, alignment: .left) From 30b3df3be1f39ffd08c04ca0779e2ae7b0dce14e Mon Sep 17 00:00:00 2001 From: QSD_e Date: Thu, 6 May 2021 14:09:55 +0200 Subject: [PATCH 4/4] issue #193 parse attachment name and file size --- FlowCrypt/Controllers/Msg/MessageViewController.swift | 2 +- FlowCrypt/Core/CoreTypes.swift | 10 ++++++++-- FlowCryptUI/Nodes/AttachmentNode.swift | 9 +++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/FlowCrypt/Controllers/Msg/MessageViewController.swift b/FlowCrypt/Controllers/Msg/MessageViewController.swift index c5882c475..0272ccfd7 100644 --- a/FlowCrypt/Controllers/Msg/MessageViewController.swift +++ b/FlowCrypt/Controllers/Msg/MessageViewController.swift @@ -174,7 +174,7 @@ extension MessageViewController { let decryptErrBlocks = decrypted.blocks.filter { $0.decryptErr != nil } let decryptAttBlocks = decrypted.blocks.filter { $0.type == .plainAtt || $0.type == .encryptedAtt || $0.type == .decryptedAtt } - let attachments = decryptAttBlocks.map { _ in Attachment(name: "Attachment", size: "10 MB") } + let attachments = decryptAttBlocks.map { Attachment(name: $0.attMeta?.name ?? "Attachment", size: $0.attMeta?.length ?? 0) } self.attachments = attachments let message: NSAttributedString diff --git a/FlowCrypt/Core/CoreTypes.swift b/FlowCrypt/Core/CoreTypes.swift index 5b3e7c7db..49a0ccd22 100644 --- a/FlowCrypt/Core/CoreTypes.swift +++ b/FlowCrypt/Core/CoreTypes.swift @@ -124,15 +124,15 @@ struct SendableMsg { struct MsgBlock: Decodable { static func blockParseErr(with content: String) -> MsgBlock { - MsgBlock(type: .blockParseErr, content: content, decryptErr: nil, keyDetails: nil) + MsgBlock(type: .blockParseErr, content: content, decryptErr: nil, keyDetails: nil, attMeta: nil) } let type: BlockType let content: String let decryptErr: DecryptErr? // always present in decryptErr BlockType let keyDetails: KeyDetails? // always present in publicKey BlockType + let attMeta: AttMeta? // always present in plainAtt, encryptedAtt, decryptedAtt, encryptedAttLink // let verifyRes: VerifyRes?, - // let attMeta: AttMeta?; // always present in plainAtt, encryptedAtt, decryptedAtt, encryptedAttLink // let signature: String? // possibly not neded in Swift @@ -166,6 +166,12 @@ struct MsgBlock: Decodable { } } + struct AttMeta: Decodable { + let name: String + let data: Data + let length: Int + } + enum BlockType: String, Decodable { case plainHtml // all content blocks, regardless if encrypted or not, formatted as a plainHtml (todo - rename this one day to formattedHtml) case publicKey diff --git a/FlowCryptUI/Nodes/AttachmentNode.swift b/FlowCryptUI/Nodes/AttachmentNode.swift index c02c521c8..163354add 100644 --- a/FlowCryptUI/Nodes/AttachmentNode.swift +++ b/FlowCryptUI/Nodes/AttachmentNode.swift @@ -13,10 +13,10 @@ public struct Attachment { public init( name: String, - size: String + size: Int ) { self.name = name - self.size = size + self.size = ByteCountFormatter.string(fromByteCount: Int64(size), countStyle: .file) } } @@ -68,7 +68,6 @@ public final class AttachmentNode: CellNode { private let subtitleNode = ASTextNode2() private let imageNode = ASImageNode() private let buttonNode = ASButtonNode() - private let separatorNode = ASDisplayNode() private var onTap: (() -> Void)? @@ -95,8 +94,6 @@ public final class AttachmentNode: CellNode { verticalStack.spacing = 3 verticalStack.style.flexShrink = 1.0 verticalStack.style.flexGrow = 1.0 - separatorNode.style.flexGrow = 1.0 - separatorNode.style.preferredSize.height = 1.0 verticalStack.children = [titleNode, subtitleNode] @@ -105,7 +102,7 @@ public final class AttachmentNode: CellNode { spacing: 10, justifyContent: .start, alignItems: .center, - children: [imageNode, verticalStack, separatorNode, buttonNode] + children: [imageNode, verticalStack, buttonNode] ) return ASInsetLayoutSpec(