This commit is contained in:
fmodf 2024-07-11 17:14:31 +02:00
parent f89831f82d
commit 07993baddc
3 changed files with 27 additions and 11 deletions

View file

@ -2,6 +2,7 @@ enum ConversationAction: Codable {
case makeConversationActive(chat: Chat, roster: Roster?)
case messagesUpdated(messages: [Message])
case attachmentsUpdated(attachments: [Attachment])
case sendMessage(from: String, to: String, body: String)
case setReplyText(String)

View file

@ -301,8 +301,21 @@ private extension DatabaseMiddleware {
.publisher(in: database._db, scheduling: .immediate)
.sink { _ in
} receiveValue: { messages in
var attachments: [Attachment] = []
for message in messages {
do {
try self.database._db.read { db in
if let attachment = try message.attachment.fetchOne(db) {
attachments.append(attachment)
}
}
} catch {
print("Failed to fetch attachment for message \(message.id): \(error)")
}
}
DispatchQueue.main.async {
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
store.dispatch(.conversationAction(.attachmentsUpdated(attachments: attachments)))
}
}
.store(in: &conversationCancellables)

View file

@ -6,9 +6,10 @@ struct ConversationMessageContainer: View {
let isOutgoing: Bool
var body: some View {
if let msgText = message.body {
if msgText.isLocation {
if let msgText = message.body, msgText.isLocation {
EmbededMapView(location: msgText.getLatLon)
} else if let attachmentId = message.attachmentId {
AttachmentView(attachmentId: attachmentId)
} else {
Text(message.body ?? "...")
.font(.body2)
@ -16,13 +17,6 @@ struct ConversationMessageContainer: View {
.multilineTextAlignment(.leading)
.padding(10)
}
} else {
Text("...")
.font(.body2)
.foregroundColor(.Material.Text.main)
.multilineTextAlignment(.leading)
.padding(10)
}
}
}
@ -71,3 +65,11 @@ private struct EmbededMapView: View {
}
}
}
private struct AttachmentView: View {
let attachmentId: String
var body: some View {
Text("Attachment \(attachmentId)")
}
}