wip
This commit is contained in:
parent
f89831f82d
commit
07993baddc
|
@ -2,6 +2,7 @@ enum ConversationAction: Codable {
|
||||||
case makeConversationActive(chat: Chat, roster: Roster?)
|
case makeConversationActive(chat: Chat, roster: Roster?)
|
||||||
|
|
||||||
case messagesUpdated(messages: [Message])
|
case messagesUpdated(messages: [Message])
|
||||||
|
case attachmentsUpdated(attachments: [Attachment])
|
||||||
|
|
||||||
case sendMessage(from: String, to: String, body: String)
|
case sendMessage(from: String, to: String, body: String)
|
||||||
case setReplyText(String)
|
case setReplyText(String)
|
||||||
|
|
|
@ -301,8 +301,21 @@ private extension DatabaseMiddleware {
|
||||||
.publisher(in: database._db, scheduling: .immediate)
|
.publisher(in: database._db, scheduling: .immediate)
|
||||||
.sink { _ in
|
.sink { _ in
|
||||||
} receiveValue: { messages 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 {
|
DispatchQueue.main.async {
|
||||||
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
store.dispatch(.conversationAction(.messagesUpdated(messages: messages)))
|
||||||
|
store.dispatch(.conversationAction(.attachmentsUpdated(attachments: attachments)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &conversationCancellables)
|
.store(in: &conversationCancellables)
|
||||||
|
|
|
@ -6,18 +6,12 @@ struct ConversationMessageContainer: View {
|
||||||
let isOutgoing: Bool
|
let isOutgoing: Bool
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if let msgText = message.body {
|
if let msgText = message.body, msgText.isLocation {
|
||||||
if msgText.isLocation {
|
EmbededMapView(location: msgText.getLatLon)
|
||||||
EmbededMapView(location: msgText.getLatLon)
|
} else if let attachmentId = message.attachmentId {
|
||||||
} else {
|
AttachmentView(attachmentId: attachmentId)
|
||||||
Text(message.body ?? "...")
|
|
||||||
.font(.body2)
|
|
||||||
.foregroundColor(.Material.Text.main)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
.padding(10)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Text("...")
|
Text(message.body ?? "...")
|
||||||
.font(.body2)
|
.font(.body2)
|
||||||
.foregroundColor(.Material.Text.main)
|
.foregroundColor(.Material.Text.main)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
|
@ -71,3 +65,11 @@ private struct EmbededMapView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct AttachmentView: View {
|
||||||
|
let attachmentId: String
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text("Attachment \(attachmentId)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue