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() } } }