From d43ae1664ae3d6434b6eab14b744bbce42d8402a Mon Sep 17 00:00:00 2001 From: Evgenii Kievsky Date: Thu, 18 Nov 2021 22:10:31 +0200 Subject: [PATCH] change title of sent part --- .../Controllers/Inbox/InboxProviders.swift | 4 +- .../Controllers/Inbox/InboxRenderable.swift | 38 ++++++++++++++++--- .../Threads/ThreadDetailsViewController.swift | 4 +- .../Mail Provider/Gmail/GmailService.swift | 1 + .../MessagesList Provider/Model/Message.swift | 5 ++- .../Threads/MessagesThreadProvider.swift | 5 ++- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/FlowCrypt/Controllers/Inbox/InboxProviders.swift b/FlowCrypt/Controllers/Inbox/InboxProviders.swift index a3c256c16..de4e23bb5 100644 --- a/FlowCrypt/Controllers/Inbox/InboxProviders.swift +++ b/FlowCrypt/Controllers/Inbox/InboxProviders.swift @@ -29,7 +29,9 @@ class InboxMessageThreadsProvider: InboxDataProvider { override func fetchInboxItems(using context: FetchMessageContext) async throws -> InboxContext { let result = try await provider.fetchThreads(using: context) - let inboxData = result.threads.map(InboxRenderable.init) + let inboxData = result.threads.map { thread in + return InboxRenderable(thread: thread, folderPath: context.folderPath ?? "") + } let inboxContext = InboxContext( data: inboxData, pagination: result.pagination diff --git a/FlowCrypt/Controllers/Inbox/InboxRenderable.swift b/FlowCrypt/Controllers/Inbox/InboxRenderable.swift index 22e227d35..7d888b117 100644 --- a/FlowCrypt/Controllers/Inbox/InboxRenderable.swift +++ b/FlowCrypt/Controllers/Inbox/InboxRenderable.swift @@ -45,12 +45,10 @@ extension InboxRenderable { self.wrappedType = .message(message) } - init(thread: MessageThread) { - let sender = thread.messages.compactMap(\.sender) - .compactMap { $0.components(separatedBy: "@").first ?? "" } - .unique() - .joined(separator: ",") - self.title = sender + init(thread: MessageThread, folderPath: String) { + + self.title = InboxRenderable.messageTitle(with: thread, and: folderPath) + self.messageCount = thread.messages.count self.subtitle = thread.subject ?? "message_missed_subject".localized self.isRead = !thread.messages @@ -65,4 +63,32 @@ extension InboxRenderable { self.date = date ?? Date() self.wrappedType = .thread(thread) } + + private static func messageTitle(with thread: MessageThread, and folderPath: String) -> String { + guard let myEmail = DataService.shared.email else { return "" } + + // for now its not exactly clear how titles on other folders should looks like + // so in scope of this PR we are applying this title presentation only for "sent" folder + if folderPath == MessageLabelType.sent.value { + var emails = thread.messages.compactMap(\.sender).unique() + // if we have only one email, it means that it could be "me" and we are not + // clearing our own email from that + if emails.count > 1 { + if let i = emails.firstIndex(of: myEmail) { + emails.remove(at: i) + } + } + let recipients = emails + .compactMap { $0.components(separatedBy: "@").first } + .joined(separator: ",") + return "To: \(recipients)" + + } else { + return thread.messages + .compactMap(\.sender) + .compactMap { $0.components(separatedBy: "@").first } + .unique() + .joined(separator: ",") + } + } } diff --git a/FlowCrypt/Controllers/Threads/ThreadDetailsViewController.swift b/FlowCrypt/Controllers/Threads/ThreadDetailsViewController.swift index 9031db9c4..72300035f 100644 --- a/FlowCrypt/Controllers/Threads/ThreadDetailsViewController.swift +++ b/FlowCrypt/Controllers/Threads/ThreadDetailsViewController.swift @@ -313,7 +313,7 @@ extension ThreadDetailsViewController { extension ThreadDetailsViewController: MessageActionsHandler { private func handleSuccessfulMessage(action: MessageAction) { hideSpinner() - onComplete(action, .init(thread: thread)) + onComplete(action, .init(thread: thread, folderPath: currentFolderPath)) navigationController?.popViewController(animated: true) } @@ -429,7 +429,7 @@ extension ThreadDetailsViewController: NavigationChildController { func handleBackButtonTap() { let isRead = input.contains(where: { $0.rawMessage.isMessageRead }) logger.logInfo("Back button. Are all messages read \(isRead) ") - onComplete(MessageAction.markAsRead(isRead), .init(thread: thread)) + onComplete(MessageAction.markAsRead(isRead), .init(thread: thread, folderPath: currentFolderPath)) navigationController?.popViewController(animated: true) } } diff --git a/FlowCrypt/Functionality/Mail Provider/Gmail/GmailService.swift b/FlowCrypt/Functionality/Mail Provider/Gmail/GmailService.swift index 9b4dc5bad..dc0407985 100644 --- a/FlowCrypt/Functionality/Mail Provider/Gmail/GmailService.swift +++ b/FlowCrypt/Functionality/Mail Provider/Gmail/GmailService.swift @@ -52,5 +52,6 @@ extension String { static let from = "from" static let subject = "subject" static let date = "date" + static let to = "to" static let identifier = "Message-ID" } diff --git a/FlowCrypt/Functionality/Mail Provider/MessagesList Provider/Model/Message.swift b/FlowCrypt/Functionality/Mail Provider/MessagesList Provider/Model/Message.swift index 93191aab5..06c7dfb65 100644 --- a/FlowCrypt/Functionality/Mail Provider/MessagesList Provider/Model/Message.swift +++ b/FlowCrypt/Functionality/Mail Provider/MessagesList Provider/Model/Message.swift @@ -14,6 +14,7 @@ struct Message: Hashable { let identifier: Identifier let date: Date let sender: String? + let recipient: String? let subject: String? let size: Int? let attachmentIds: [String] @@ -45,7 +46,8 @@ struct Message: Hashable { attachmentIds: [String], threadId: String? = nil, draftIdentifier: String? = nil, - raw: String? = nil + raw: String? = nil, + recipient: String? = nil ) { self.identifier = identifier self.date = date @@ -57,6 +59,7 @@ struct Message: Hashable { self.threadId = threadId self.draftIdentifier = draftIdentifier self.raw = raw + self.recipient = recipient } } diff --git a/FlowCrypt/Functionality/Mail Provider/Threads/MessagesThreadProvider.swift b/FlowCrypt/Functionality/Mail Provider/Threads/MessagesThreadProvider.swift index 43156591a..526d489bb 100644 --- a/FlowCrypt/Functionality/Mail Provider/Threads/MessagesThreadProvider.swift +++ b/FlowCrypt/Functionality/Mail Provider/Threads/MessagesThreadProvider.swift @@ -147,6 +147,7 @@ extension Message { var sender: String? var subject: String? + var recipient: String? messageHeaders.compactMap { $0 }.forEach { guard let name = $0.name?.lowercased() else { return } @@ -154,6 +155,7 @@ extension Message { switch name { case .from: sender = value case .subject: subject = value + case .to: recipient = value default: break } } @@ -175,7 +177,8 @@ extension Message { attachmentIds: attachmentsIds, threadId: message.threadId, draftIdentifier: draftIdentifier, - raw: message.raw + raw: message.raw, + recipient: recipient ) } }