Skip to content
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

fix: Show not inline files #1689

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions Mail/Views/Thread/Message/Attachment/AttachmentsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ struct AttachmentsView: View {
@State private var trackDownloadTask: [String: Task<Void, Error>] = [:]
@State private var isDownloadDisabled = false

private var attachments: [Attachment] {
return message.attachments.filter { $0.disposition == .attachment || $0.contentId == nil }
}
let attachments: [Attachment]

private var formattedText: String {
var text = [String]()
Expand Down Expand Up @@ -232,5 +230,5 @@ struct DownloadAllAttachmentsButtonView: View {
}

#Preview {
AttachmentsView(message: PreviewHelper.sampleMessage)
AttachmentsView(message: PreviewHelper.sampleMessage, attachments: [])
}
6 changes: 3 additions & 3 deletions Mail/Views/Thread/Message/MessageSubHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ struct MessageSubHeaderView: View {
.padding(.horizontal, value: .medium)
}

if !message.attachments.filter({ $0.disposition == .attachment || $0.contentId == nil }).isEmpty || message
.swissTransferUuid != nil {
AttachmentsView(message: message)
if !message.notInlineAttachments.isEmpty
|| message.swissTransferUuid != nil {
AttachmentsView(message: message, attachments: Array(message.notInlineAttachments))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import RealmSwift
extension MailboxInfosManager: RealmConfigurable {}

public final class MailboxInfosManager {
private static let currentDbVersion: UInt64 = 8
private static let currentDbVersion: UInt64 = 9
private let dbName = "MailboxInfos.realm"

public let realmConfiguration: Realm.Configuration
Expand Down
10 changes: 10 additions & 0 deletions MailCore/Cache/MailboxManager/MailboxManager+Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ public extension MailboxManager {
let completedMessage = try await apiFetcher.message(message: message)
completedMessage.fullyDownloaded = true

for attachment in completedMessage.attachments {
if attachment.disposition == .attachment || attachment.contentId == nil {
attachment.isInline = false
} else if let contentId = attachment.contentId {
attachment.isInline = completedMessage.body?.value?.contains(contentId) == true
} else {
attachment.isInline = true
}
}

// Update message in Realm
try? writeTransaction { writableRealm in
writableRealm.add(completedMessage, update: .modified)
Expand Down
1 change: 1 addition & 0 deletions MailCore/Models/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Attachment: /* Hashable, */ EmbeddedObject, Codable, Identifiable {
@Persisted(originProperty: "attachments") var parentLink: LinkingObjects<Message>
@Persisted public var saved = false
@Persisted public var temporaryLocalUrl: String?
@Persisted public var isInline: Bool

public var parent: Message? {
return parentLink.first
Expand Down
4 changes: 4 additions & 0 deletions MailCore/Models/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public final class Message: Object, Decodable, Identifiable {
return Array(dup)
}

public var notInlineAttachments: Results<Attachment> {
attachments.filter("isInline == false")
}

public func fromMe(currentMailboxEmail: String) -> Bool {
return from.contains { $0.isMe(currentMailboxEmail: currentMailboxEmail) }
}
Expand Down
Loading