add attachment CRUD to MailStore, wire hasAttachments in Queries
This commit is contained in:
@@ -448,6 +448,66 @@ public final class MailStore: Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Attachments
|
||||
|
||||
public func insertAttachment(_ attachment: AttachmentRecord) throws {
|
||||
try dbWriter.write { db in
|
||||
try attachment.insert(db)
|
||||
}
|
||||
}
|
||||
|
||||
public func insertAttachments(_ attachments: [AttachmentRecord]) throws {
|
||||
try dbWriter.write { db in
|
||||
for attachment in attachments {
|
||||
try attachment.insert(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func attachments(messageId: String) throws -> [AttachmentRecord] {
|
||||
try dbWriter.read { db in
|
||||
try AttachmentRecord
|
||||
.filter(Column("messageId") == messageId)
|
||||
.order(Column("filename"))
|
||||
.fetchAll(db)
|
||||
}
|
||||
}
|
||||
|
||||
public func updateAttachmentCachePath(id: String, cachePath: String) throws {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(
|
||||
sql: "UPDATE attachment SET cachePath = ? WHERE id = ?",
|
||||
arguments: [cachePath, id]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func updateHasAttachments(messageId: String, hasAttachments: Bool) throws {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(
|
||||
sql: "UPDATE message SET hasAttachments = ? WHERE id = ?",
|
||||
arguments: [hasAttachments, messageId]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func storeBodyWithAttachments(
|
||||
messageId: String,
|
||||
text: String?,
|
||||
html: String?,
|
||||
attachments: [AttachmentRecord]
|
||||
) throws {
|
||||
try dbWriter.write { db in
|
||||
try db.execute(
|
||||
sql: "UPDATE message SET bodyText = ?, bodyHtml = ?, hasAttachments = ? WHERE id = ?",
|
||||
arguments: [text, html, !attachments.isEmpty, messageId]
|
||||
)
|
||||
for attachment in attachments {
|
||||
try attachment.insert(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Task cache queries
|
||||
|
||||
public func insertTask(_ task: TaskRecord) throws {
|
||||
|
||||
@@ -99,7 +99,7 @@ extension MailStore {
|
||||
bodyHtml: record.bodyHtml,
|
||||
isRead: record.isRead,
|
||||
isFlagged: record.isFlagged,
|
||||
hasAttachments: false
|
||||
hasAttachments: record.hasAttachments
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user