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.
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.navigationTitle(conversation.effectiveDisplayName)
|
|
|
|
.onChange(of: messages) { newValue in
|
|
|
|
proxy.scrollTo(newValue.last, anchor: .bottom)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ConversationViewWrapper : View {
|
|
|
|
var conversation: Conversation
|
|
|
|
@State private var messages = [Message]()
|
|
|
|
@EnvironmentObject private var connection: Connection
|
|
|
|
|
|
|
|
private func refresh() {
|
|
|
|
messages.removeAll()
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|