ios: improve connection error alerts
This commit is contained in:
@@ -55,7 +55,7 @@ final class AlertManager: ObservableObject {
|
|||||||
|
|
||||||
func showAlert(_ alert: Alert) {
|
func showAlert(_ alert: Alert) {
|
||||||
logger.debug("AlertManager.showAlert")
|
logger.debug("AlertManager.showAlert")
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||||
self.alertView = alert
|
self.alertView = alert
|
||||||
self.presentAlert = true
|
self.presentAlert = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ enum ChatResponse: Decodable, Error {
|
|||||||
case invitation(connReqInvitation: String)
|
case invitation(connReqInvitation: String)
|
||||||
case sentConfirmation
|
case sentConfirmation
|
||||||
case sentInvitation
|
case sentInvitation
|
||||||
|
case contactAlreadyExists(contact: Contact)
|
||||||
case contactDeleted(contact: Contact)
|
case contactDeleted(contact: Contact)
|
||||||
case userProfileNoChange
|
case userProfileNoChange
|
||||||
case userProfileUpdated(fromProfile: Profile, toProfile: Profile)
|
case userProfileUpdated(fromProfile: Profile, toProfile: Profile)
|
||||||
@@ -161,6 +162,7 @@ enum ChatResponse: Decodable, Error {
|
|||||||
case .invitation: return "invitation"
|
case .invitation: return "invitation"
|
||||||
case .sentConfirmation: return "sentConfirmation"
|
case .sentConfirmation: return "sentConfirmation"
|
||||||
case .sentInvitation: return "sentInvitation"
|
case .sentInvitation: return "sentInvitation"
|
||||||
|
case .contactAlreadyExists: return "contactAlreadyExists"
|
||||||
case .contactDeleted: return "contactDeleted"
|
case .contactDeleted: return "contactDeleted"
|
||||||
case .userProfileNoChange: return "userProfileNoChange"
|
case .userProfileNoChange: return "userProfileNoChange"
|
||||||
case .userProfileUpdated: return "userProfileUpdated"
|
case .userProfileUpdated: return "userProfileUpdated"
|
||||||
@@ -204,6 +206,7 @@ enum ChatResponse: Decodable, Error {
|
|||||||
case let .invitation(connReqInvitation): return connReqInvitation
|
case let .invitation(connReqInvitation): return connReqInvitation
|
||||||
case .sentConfirmation: return noDetails
|
case .sentConfirmation: return noDetails
|
||||||
case .sentInvitation: return noDetails
|
case .sentInvitation: return noDetails
|
||||||
|
case let .contactAlreadyExists(contact): return String(describing: contact)
|
||||||
case let .contactDeleted(contact): return String(describing: contact)
|
case let .contactDeleted(contact): return String(describing: contact)
|
||||||
case .userProfileNoChange: return noDetails
|
case .userProfileNoChange: return noDetails
|
||||||
case let .userProfileUpdated(_, toProfile): return String(describing: toProfile)
|
case let .userProfileUpdated(_, toProfile): return String(describing: toProfile)
|
||||||
@@ -435,11 +438,36 @@ func apiAddContact() throws -> String {
|
|||||||
throw r
|
throw r
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiConnect(connReq: String) async throws {
|
func apiConnect(connReq: String) async throws -> Bool {
|
||||||
let r = await chatSendCmd(.connect(connReq: connReq))
|
let r = await chatSendCmd(.connect(connReq: connReq))
|
||||||
|
let am = AlertManager.shared
|
||||||
switch r {
|
switch r {
|
||||||
case .sentConfirmation: return
|
case .sentConfirmation: return true
|
||||||
case .sentInvitation: return
|
case .sentInvitation: return true
|
||||||
|
case let .contactAlreadyExists(contact):
|
||||||
|
am.showAlertMsg(
|
||||||
|
title: "Contact already exists",
|
||||||
|
message: "You are already connected to \(contact.displayName) via this link."
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
case .chatCmdError(.error(.invalidConnReq)):
|
||||||
|
am.showAlertMsg(
|
||||||
|
title: "Invalid connection link",
|
||||||
|
message: "Please check that you used the correct link or ask your contact to send you another one."
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
case .chatCmdError(.errorAgent(.BROKER(.TIMEOUT))):
|
||||||
|
am.showAlertMsg(
|
||||||
|
title: "Connection timeout",
|
||||||
|
message: "Please check your network connection and try again"
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
case .chatCmdError(.errorAgent(.BROKER(.NETWORK))):
|
||||||
|
am.showAlertMsg(
|
||||||
|
title: "Connection error",
|
||||||
|
message: "Please check your network connection and try again"
|
||||||
|
)
|
||||||
|
return false
|
||||||
default: throw r
|
default: throw r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,10 @@ struct ChatListView: View {
|
|||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
try await apiConnect(connReq: link)
|
let ok = try await apiConnect(connReq: link)
|
||||||
|
if ok {
|
||||||
connectionReqSentAlert(action == "contact" ? .contact : .invitation)
|
connectionReqSentAlert(action == "contact" ? .contact : .invitation)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
let err = error.localizedDescription
|
let err = error.localizedDescription
|
||||||
AlertManager.shared.showAlertMsg(title: "Connection error", message: err)
|
AlertManager.shared.showAlertMsg(title: "Connection error", message: err)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import SwiftUI
|
|||||||
import CodeScanner
|
import CodeScanner
|
||||||
|
|
||||||
struct ConnectContactView: View {
|
struct ConnectContactView: View {
|
||||||
var completed: ((Error?) -> Void)
|
var completed: ((Result<Bool, Error>) -> Void)
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@@ -35,16 +35,16 @@ struct ConnectContactView: View {
|
|||||||
case let .success(r):
|
case let .success(r):
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
try await apiConnect(connReq: r.string)
|
let ok = try await apiConnect(connReq: r.string)
|
||||||
completed(nil)
|
completed(.success(ok))
|
||||||
} catch {
|
} catch {
|
||||||
logger.error("ConnectContactView.processQRCode apiConnect error: \(error.localizedDescription)")
|
logger.error("ConnectContactView.processQRCode apiConnect error: \(error.localizedDescription)")
|
||||||
completed(error)
|
completed(.failure(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case let .failure(e):
|
case let .failure(e):
|
||||||
logger.error("ConnectContactView.processQRCode QR code error: \(e.localizedDescription)")
|
logger.error("ConnectContactView.processQRCode QR code error: \(e.localizedDescription)")
|
||||||
completed(e)
|
completed(.failure(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,10 +54,11 @@ struct NewChatButton: View {
|
|||||||
ConnectContactView(completed: { err in
|
ConnectContactView(completed: { err in
|
||||||
connectContact = false
|
connectContact = false
|
||||||
DispatchQueue.global().async {
|
DispatchQueue.global().async {
|
||||||
if let error = err {
|
switch (err) {
|
||||||
|
case let .success(ok):
|
||||||
|
if ok { connectionReqSentAlert(.invitation) }
|
||||||
|
case let .failure(error):
|
||||||
connectionErrorAlert(error)
|
connectionErrorAlert(error)
|
||||||
} else {
|
|
||||||
connectionReqSentAlert(.invitation)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user