Kordophone client for iOS and macOS
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.

55 lines
1.5 KiB

3 years ago
import SwiftUI
import KordophoneKit
struct ConversationView : View {
var conversation: Conversation
var messages: [Message]
var body: some View {
ScrollViewReader { proxy in
ScrollView {
LazyVStack {
ForEach(messages) { message in
if message.sentByMe {
Spacer()
}
MessageView(message: message)
.id(message)
if !message.sentByMe {
Spacer()
}
3 years ago
}
}
}
.navigationTitle(conversation.effectiveDisplayName)
.onChange(of: messages) { newValue in
proxy.scrollTo(newValue.last, anchor: .bottom)
}
3 years ago
}
}
}
struct ConversationViewWrapper : View {
var conversation: Conversation
@State private var messages = [Message]()
@EnvironmentObject private var connection: Connection
private func refresh() {
messages.removeAll()
3 years ago
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()
}
}
}