2024-06-19 15:15:27 +00:00
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import Martin
|
|
|
|
import SwiftUI
|
|
|
|
|
2024-06-21 10:42:50 +00:00
|
|
|
struct ConversationScreen: View {
|
|
|
|
@EnvironmentObject var store: AppStore
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
var body: some View {
|
2024-06-24 13:28:26 +00:00
|
|
|
ZStack {
|
|
|
|
// Background color
|
|
|
|
Color.Main.backgroundLight
|
|
|
|
.ignoresSafeArea()
|
2024-06-19 15:15:27 +00:00
|
|
|
|
2024-06-24 13:28:26 +00:00
|
|
|
// Content
|
|
|
|
VStack(spacing: 0) {
|
|
|
|
// Header
|
|
|
|
ConversationScreenHeader()
|
|
|
|
|
|
|
|
// Msg list
|
|
|
|
let messages = store.state.conversationsState.currentMessages
|
|
|
|
if !messages.isEmpty {
|
|
|
|
List {
|
|
|
|
ForEach(messages) { message in
|
|
|
|
ConversationMessageRow(message: message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.listStyle(.plain)
|
|
|
|
.background(Color.Main.backgroundLight)
|
|
|
|
} else {
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-21 10:42:50 +00:00
|
|
|
private struct ConversationScreenHeader: View {
|
2024-06-19 15:15:27 +00:00
|
|
|
// @EnvironmentObject var state: AppState
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ZStack {
|
|
|
|
// bg
|
|
|
|
Color.Main.backgroundDark
|
|
|
|
.ignoresSafeArea()
|
|
|
|
|
|
|
|
// title
|
|
|
|
// let name = (
|
|
|
|
// state.activeConversation?.participant?.name ??
|
|
|
|
// state.activeConversation.participant?.contactBareJid
|
|
|
|
// ) ?? L10n.Chat.title
|
|
|
|
Text(L10n.Chat.title)
|
|
|
|
.font(.head2)
|
|
|
|
.foregroundColor(Color.Main.black)
|
|
|
|
|
|
|
|
HStack {
|
|
|
|
Image(systemName: "chevron.left")
|
|
|
|
.foregroundColor(Color.Tango.orangeMedium)
|
|
|
|
.tappablePadding(.symmetric(12)) {
|
2024-06-21 10:42:50 +00:00
|
|
|
store.dispatch(.changeFlow(store.state.previousFlow))
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
// Image(systemName: "plus.viewfinder")
|
|
|
|
// .foregroundColor(Color.Tango.orangeMedium)
|
|
|
|
// .tappablePadding(.symmetric(12)) {
|
|
|
|
// print("Scan QR-code")
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
.padding(.horizontal, 16)
|
|
|
|
}
|
|
|
|
.frame(height: 44)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 13:28:26 +00:00
|
|
|
private struct ConversationMessageRow: View {
|
|
|
|
@EnvironmentObject var store: AppStore
|
2024-06-19 15:15:27 +00:00
|
|
|
|
|
|
|
let message: Message
|
|
|
|
|
|
|
|
var body: some View {
|
2024-06-24 13:28:26 +00:00
|
|
|
VStack {
|
|
|
|
if isIncoming() {
|
|
|
|
HStack {
|
|
|
|
MessageContainer(message: message, isOutgoing: false)
|
|
|
|
.padding(.all, 8)
|
|
|
|
Spacer()
|
|
|
|
.frame(minWidth: 48, maxWidth: .infinity, alignment: .leading)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
|
|
|
.frame(minWidth: 48, maxWidth: .infinity, alignment: .leading)
|
|
|
|
MessageContainer(message: message, isOutgoing: true)
|
|
|
|
.padding(.all, 8)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// HStack {
|
2024-06-19 15:15:27 +00:00
|
|
|
// if isIncoming() {
|
2024-06-24 13:28:26 +00:00
|
|
|
// HStack
|
2024-06-19 15:15:27 +00:00
|
|
|
// }
|
2024-06-24 13:28:26 +00:00
|
|
|
// // if isIncoming() {
|
|
|
|
// // Image(systemName: "person.fill")
|
|
|
|
// // .foregroundColor(Color.Main.black)
|
|
|
|
// // .frame(width: 32, height: 32)
|
|
|
|
// // .background(Color.Main.backgroundLight)
|
|
|
|
// // .clipShape(Circle())
|
|
|
|
// // Text(message.body ?? "...")
|
|
|
|
// // .padding(.all, 8)
|
|
|
|
// // .background(Color.Main.backgroundLight)
|
|
|
|
// // .clipShape(RoundedRectangle(cornerRadius: 8))
|
|
|
|
// // .foregroundColor(Color.Main.black)
|
|
|
|
// // } else {
|
|
|
|
// // Text(message.body ?? "--NO BODY?--")
|
|
|
|
// // .padding(.all, 8)
|
|
|
|
// // .background(Color.Main.backgroundLight)
|
|
|
|
// // .clipShape(RoundedRectangle(cornerRadius: 8))
|
|
|
|
// // .foregroundColor(Color.Main.black)
|
|
|
|
// // Image(systemName: "person.fill")
|
|
|
|
// // .foregroundColor(Color.Main.black)
|
|
|
|
// // .frame(width: 32, height: 32)
|
|
|
|
// // .background(Color.Main.backgroundLight)
|
|
|
|
// // .clipShape(Circle())
|
|
|
|
// // }
|
|
|
|
// }
|
|
|
|
// .padding(.horizontal, 16)
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
2024-06-24 13:28:26 +00:00
|
|
|
.sharedListRow()
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2024-06-24 13:28:26 +00:00
|
|
|
private func isIncoming() -> Bool {
|
|
|
|
message.from != store.state.conversationsState.currentChat?.account
|
|
|
|
}
|
2024-06-19 15:15:27 +00:00
|
|
|
}
|