aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Managers
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/Managers')
-rw-r--r--Hotline/Managers/ChatStore.swift26
1 files changed, 26 insertions, 0 deletions
diff --git a/Hotline/Managers/ChatStore.swift b/Hotline/Managers/ChatStore.swift
index daf8ca0..59c9484 100644
--- a/Hotline/Managers/ChatStore.swift
+++ b/Hotline/Managers/ChatStore.swift
@@ -28,12 +28,23 @@ actor ChatStore {
}
}
+ struct EntryMetadata: Codable {
+ var images: [ImageMetadata]?
+
+ struct ImageMetadata: Codable {
+ let url: String
+ let width: CGFloat?
+ let height: CGFloat?
+ }
+ }
+
struct Entry: Codable {
let id: UUID
let body: String
let username: String?
let type: String
let date: Date
+ var metadata: EntryMetadata?
}
struct LoadResult {
@@ -81,6 +92,21 @@ actor ChatStore {
}
}
+ func updateMetadata(_ metadata: EntryMetadata, for entryID: UUID, key: SessionKey) async {
+ do {
+ guard var logFile = try loadLogFile(for: key) else { return }
+
+ if let index = logFile.entries.firstIndex(where: { $0.id == entryID }) {
+ logFile.entries[index].metadata = metadata
+ cache[key] = logFile
+ try persist(logFile, for: key)
+ }
+ }
+ catch {
+ print("ChatStore: failed to update metadata —", error)
+ }
+ }
+
func loadHistory(for key: SessionKey, limit: Int? = nil) async -> LoadResult {
do {
let logFile = try loadLogFile(for: key)