mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-01 11:46:10 +00:00
* send messages from chats * update API to use chat IDs * send messages to groups * generate invitation QR code * connect via QR code
63 lines
1.7 KiB
Swift
63 lines
1.7 KiB
Swift
//
|
|
// ChatView.swift
|
|
// SimpleX
|
|
//
|
|
// Created by Evgeny Poberezkin on 27/01/2022.
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ChatView: View {
|
|
@EnvironmentObject var chatModel: ChatModel
|
|
@State var inProgress: Bool = false
|
|
|
|
var chatInfo: ChatInfo
|
|
var body: some View {
|
|
VStack {
|
|
if let chat: Chat = chatModel.chats[chatInfo.id] {
|
|
VStack {
|
|
ScrollView {
|
|
LazyVStack {
|
|
ForEach(chat.chatItems) { chatItem in
|
|
Text(chatItem.content.text)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
Text("unexpected: chat not found...")
|
|
}
|
|
|
|
Spacer()
|
|
|
|
SendMessageView(sendMessage: sendMessage, inProgress: inProgress)
|
|
}
|
|
}
|
|
|
|
func sendMessage(_ msg: String) {
|
|
do {
|
|
let chatItem = try apiSendMessage(type: chatInfo.chatType, id: chatInfo.apiId, msg: .text(msg))
|
|
let chat = chatModel.chats[chatInfo.id] ?? Chat(chatInfo: chatInfo, chatItems: [])
|
|
chatModel.chats[chatInfo.id] = chat
|
|
chat.chatItems.append(chatItem)
|
|
} catch {
|
|
print(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ChatView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
let chatModel = ChatModel()
|
|
chatModel.chats = [
|
|
"@1": Chat(
|
|
chatInfo: sampleDirectChatInfo,
|
|
chatItems: []
|
|
)
|
|
]
|
|
return ChatView(chatInfo: sampleDirectChatInfo)
|
|
.environmentObject(chatModel)
|
|
}
|
|
}
|