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-09 22:53:06 +00:00
|
|
|
@State private var showNotificationAlert = false
|
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-09 22:53:06 +00:00
|
|
|
ChatReceiver.shared.start()
|
|
|
|
NtfManager.shared.requestAuthorization(onDeny: {
|
|
|
|
showNotificationAlert = true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.alert(isPresented : $showNotificationAlert){
|
|
|
|
Alert(
|
|
|
|
title: Text("Notification are disabled!"),
|
|
|
|
message: Text("Please open settings to enable"),
|
|
|
|
primaryButton: .default(Text("Open Settings")) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
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-02-09 22:53:06 +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!")
|
|
|
|
// }
|
|
|
|
//}
|