Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion FlowCrypt/Controllers/Inbox/InboxProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 32 additions & 6 deletions FlowCrypt/Controllers/Inbox/InboxRenderable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ",")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,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)
}

Expand Down Expand Up @@ -488,7 +488,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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -57,6 +59,7 @@ struct Message: Hashable {
self.threadId = threadId
self.draftIdentifier = draftIdentifier
self.raw = raw
self.recipient = recipient
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ extension Message {

var sender: String?
var subject: String?
var recipient: String?

messageHeaders.compactMap { $0 }.forEach {
guard let name = $0.name?.lowercased() else { return }
let value = $0.value
switch name {
case .from: sender = value
case .subject: subject = value
case .to: recipient = value
default: break
}
}
Expand All @@ -175,7 +177,8 @@ extension Message {
attachmentIds: attachmentsIds,
threadId: message.threadId,
draftIdentifier: draftIdentifier,
raw: message.raw
raw: message.raw,
recipient: recipient
)
}
}