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-12 15:59:43 +00:00
|
|
|
@ObservedObject var alertManager = AlertManager.shared
|
2022-05-24 19:34:27 +01:00
|
|
|
@ObservedObject var callController = CallController.shared
|
2022-05-27 18:21:35 +04:00
|
|
|
@Binding var userAuthorized: Bool?
|
2022-02-03 07:16:29 +00:00
|
|
|
|
2022-01-21 11:09:33 +00:00
|
|
|
var body: some View {
|
2022-05-09 09:52:09 +01:00
|
|
|
ZStack {
|
2022-05-28 14:58:52 +04:00
|
|
|
if userAuthorized == true {
|
|
|
|
if let step = chatModel.onboardingStage {
|
|
|
|
if case .onboardingComplete = step,
|
|
|
|
let user = chatModel.currentUser {
|
|
|
|
ZStack(alignment: .top) {
|
|
|
|
ChatListView(user: user)
|
|
|
|
.onAppear {
|
|
|
|
NtfManager.shared.requestAuthorization(onDeny: {
|
|
|
|
alertManager.showAlert(notificationAlert())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if chatModel.showCallView, let call = chatModel.activeCall {
|
|
|
|
ActiveCallView(call: call)
|
|
|
|
}
|
|
|
|
IncomingCallView()
|
2022-05-24 19:34:27 +01:00
|
|
|
}
|
2022-05-28 14:58:52 +04:00
|
|
|
} else {
|
|
|
|
OnboardingView(onboarding: step)
|
2022-01-29 23:37:02 +00:00
|
|
|
}
|
2022-02-26 20:21:32 +00:00
|
|
|
}
|
2022-05-09 09:52:09 +01:00
|
|
|
}
|
2022-01-22 17:54:22 +00:00
|
|
|
}
|
2022-05-09 09:52:09 +01:00
|
|
|
.alert(isPresented: $alertManager.presentAlert) { alertManager.alertView! }
|
2022-02-09 22:53:06 +00:00
|
|
|
}
|
2022-02-12 15:59:43 +00:00
|
|
|
|
|
|
|
func notificationAlert() -> Alert {
|
|
|
|
Alert(
|
2022-04-16 09:37:01 +01:00
|
|
|
title: Text("Notifications are disabled!"),
|
2022-02-26 20:21:32 +00:00
|
|
|
message: Text("The app can notify you when you receive messages or contact requests - please open settings to enable."),
|
2022-02-12 15:59:43 +00:00
|
|
|
primaryButton: .default(Text("Open Settings")) {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
}
|
2022-01-21 11:09:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 09:52:09 +01:00
|
|
|
func connectViaUrl() {
|
|
|
|
let m = ChatModel.shared
|
|
|
|
if let url = m.appOpenUrl {
|
|
|
|
m.appOpenUrl = nil
|
|
|
|
AlertManager.shared.showAlert(connectViaUrlAlert(url))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func connectViaUrlAlert(_ url: URL) -> Alert {
|
|
|
|
var path = url.path
|
|
|
|
logger.debug("ChatListView.connectViaUrlAlert path: \(path)")
|
|
|
|
if (path == "/contact" || path == "/invitation") {
|
|
|
|
path.removeFirst()
|
|
|
|
let action: ConnReqType = path == "contact" ? .contact : .invitation
|
|
|
|
let link = url.absoluteString.replacingOccurrences(of: "///\(path)", with: "/\(path)")
|
|
|
|
let title: LocalizedStringKey
|
|
|
|
if case .contact = action { title = "Connect via contact link?" }
|
|
|
|
else { title = "Connect via one-time link?" }
|
|
|
|
return Alert(
|
|
|
|
title: Text(title),
|
|
|
|
message: Text("Your profile will be sent to the contact that you received this link from"),
|
|
|
|
primaryButton: .default(Text("Connect")) {
|
|
|
|
connectViaLink(link)
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return Alert(title: Text("Error: URL is invalid"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 15:59:43 +00:00
|
|
|
final class AlertManager: ObservableObject {
|
|
|
|
static let shared = AlertManager()
|
|
|
|
@Published var presentAlert = false
|
|
|
|
@Published var alertView: Alert?
|
|
|
|
|
|
|
|
func showAlert(_ alert: Alert) {
|
2022-02-14 11:53:44 +00:00
|
|
|
logger.debug("AlertManager.showAlert")
|
2022-04-02 14:35:35 +01:00
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
2022-02-12 15:59:43 +00:00
|
|
|
self.alertView = alert
|
|
|
|
self.presentAlert = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-16 09:37:01 +01:00
|
|
|
func showAlertMsg(title: LocalizedStringKey, message: LocalizedStringKey? = nil) {
|
2022-05-28 14:58:52 +04:00
|
|
|
showAlert(mkAlert(title: title, message: message))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mkAlert(title: LocalizedStringKey, message: LocalizedStringKey? = nil) -> Alert {
|
|
|
|
if let message = message {
|
|
|
|
return Alert(title: Text(title), message: Text(message))
|
|
|
|
} else {
|
|
|
|
return Alert(title: Text(title))
|
2022-02-12 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-22 17:54:22 +00:00
|
|
|
|
|
|
|
//struct ContentView_Previews: PreviewProvider {
|
|
|
|
// static var previews: some View {
|
|
|
|
// ContentView(text: "Hello!")
|
|
|
|
// }
|
|
|
|
//}
|