You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
3 years ago
|
|
||
|
import SwiftUI
|
||
|
import KordophoneKit
|
||
|
|
||
|
struct ConversationView : View {
|
||
|
var conversation: Conversation
|
||
|
var messages: [Message]
|
||
|
|
||
|
var body: some View {
|
||
|
ScrollView {
|
||
|
LazyVStack {
|
||
|
ForEach(messages) { message in
|
||
|
if message.sentByMe {
|
||
|
Spacer()
|
||
|
}
|
||
|
MessageView(message: message)
|
||
|
if !message.sentByMe {
|
||
|
Spacer()
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct ConversationViewWrapper : View {
|
||
|
var conversation: Conversation
|
||
|
@State private var messages = [Message]()
|
||
|
@EnvironmentObject private var connection: Connection
|
||
|
|
||
|
private func refresh() {
|
||
|
Task {
|
||
|
self.messages = await connection.messages(in: conversation) ?? .init()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var body: some View {
|
||
|
ConversationView(conversation: conversation, messages: messages)
|
||
|
.onChange(of: conversation, perform: { newValue in
|
||
|
refresh()
|
||
|
})
|
||
|
.onAppear {
|
||
|
refresh()
|
||
|
}
|
||
|
}
|
||
|
}
|