2022-01-21 11:09:33 +00:00
|
|
|
//
|
|
|
|
// ContentView.swift
|
|
|
|
// Shared
|
|
|
|
//
|
|
|
|
// Created by Evgeny Poberezkin on 17/01/2022.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2022-01-29 11:10:04 +00:00
|
|
|
@EnvironmentObject var chatModel: ChatModel
|
2022-02-03 07:16:29 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
var body: some View {
|
2022-01-29 11:10:04 +00:00
|
|
|
if let user = chatModel.currentUser {
|
|
|
|
ChatListView(user: user)
|
2022-01-29 23:37:02 +00:00
|
|
|
.onAppear {
|
|
|
|
do {
|
2022-02-06 18:26:22 +00:00
|
|
|
try apiStartChat()
|
2022-02-02 12:51:39 +00:00
|
|
|
chatModel.chats = try apiGetChats()
|
2022-01-29 23:37:02 +00:00
|
|
|
} catch {
|
2022-02-06 18:26:22 +00:00
|
|
|
fatalError("Failed to start or load chats: \(error)")
|
2022-01-29 23:37:02 +00:00
|
|
|
}
|
2022-02-07 10:36:11 +00:00
|
|
|
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
while(true) {
|
|
|
|
do {
|
|
|
|
try processReceivedMsg(chatModel, chatRecvMsg())
|
|
|
|
} catch {
|
|
|
|
print("error receiving message: ", error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 23:37:02 +00:00
|
|
|
}
|
2022-01-29 11:10:04 +00:00
|
|
|
} else {
|
|
|
|
WelcomeView()
|
2022-01-22 17:54:22 +00:00
|
|
|
}
|
2022-01-29 11:10:04 +00:00
|
|
|
}
|
2022-01-21 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
2022-01-22 17:54:22 +00:00
|
|
|
|
|
|
|
//struct ContentView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// ContentView(text: "Hello!")
|
|
|
|
// }
|
|
|
|
//}
|