From e44e9a0940043df1f4fa5123d7f201761c7da9ee Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sat, 3 Dec 2022 18:05:32 +0000 Subject: [PATCH] mobile: broker error type (#1475) * mobile: broker error type * fix * ios: update libraries * change AgentErrorType to String --- .../src/main/java/chat/simplex/app/model/ChatModel.kt | 2 +- .../src/main/java/chat/simplex/app/model/SimpleXAPI.kt | 9 ++++----- .../chat/simplex/app/views/chat/item/CIMetaView.kt | 2 +- .../chat/simplex/app/views/chat/item/ChatItemView.kt | 2 +- .../simplex/app/views/usersettings/SMPServerView.kt | 4 ++-- .../simplex/app/views/usersettings/SMPServersView.kt | 2 +- apps/android/app/src/main/res/values-de/strings.xml | 2 +- apps/android/app/src/main/res/values-ru/strings.xml | 2 +- apps/android/app/src/main/res/values/strings.xml | 2 +- apps/ios/Shared/Model/SimpleXAPI.swift | 10 +++++----- .../Shared/Views/Chat/ChatItem/FramedItemView.swift | 2 +- apps/ios/Shared/Views/ChatList/ChatListNavLink.swift | 8 ++++---- apps/ios/Shared/Views/UserSettings/SMPServerView.swift | 4 ++-- .../ios/Shared/Views/UserSettings/SMPServersView.swift | 2 +- apps/ios/SimpleX.xcodeproj/project.pbxproj | 10 ++++++++++ apps/ios/SimpleXChat/APITypes.swift | 4 ++-- apps/ios/SimpleXChat/ChatTypes.swift | 2 +- 17 files changed, 39 insertions(+), 30 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt b/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt index 68cad140b0..87a15394c1 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/ChatModel.kt @@ -1266,7 +1266,7 @@ sealed class CIStatus { @Serializable @SerialName("sndNew") class SndNew: CIStatus() @Serializable @SerialName("sndSent") class SndSent: CIStatus() @Serializable @SerialName("sndErrorAuth") class SndErrorAuth: CIStatus() - @Serializable @SerialName("sndError") class SndError(val agentError: AgentErrorType): CIStatus() + @Serializable @SerialName("sndError") class SndError(val agentError: String): CIStatus() @Serializable @SerialName("rcvNew") class RcvNew: CIStatus() @Serializable @SerialName("rcvRead") class RcvRead: CIStatus() } diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 3451881701..0e5c4e499a 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -28,8 +28,7 @@ import chat.simplex.app.views.call.* import chat.simplex.app.views.helpers.* import chat.simplex.app.views.newchat.ConnectViaLinkTab import chat.simplex.app.views.onboarding.OnboardingStage -import chat.simplex.app.views.usersettings.NotificationPreviewMode -import chat.simplex.app.views.usersettings.NotificationsMode +import chat.simplex.app.views.usersettings.* import kotlinx.coroutines.* import kotlinx.datetime.Clock import kotlinx.datetime.Instant @@ -958,7 +957,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a && r.chatError.agentError.brokerErr is BrokerErrorType.TIMEOUT -> { AlertManager.shared.showAlertMsg( generalGetString(R.string.connection_timeout), - generalGetString(R.string.network_error_desc) + String.format(generalGetString(R.string.network_error_desc), serverHostname(r.chatError.agentError.brokerAddress)) ) true } @@ -967,7 +966,7 @@ open class ChatController(var ctrl: ChatCtrl?, val ntfManager: NtfManager, val a && r.chatError.agentError.brokerErr is BrokerErrorType.NETWORK -> { AlertManager.shared.showAlertMsg( generalGetString(R.string.connection_error), - generalGetString(R.string.network_error_desc) + String.format(generalGetString(R.string.network_error_desc), serverHostname(r.chatError.agentError.brokerAddress)) ) true } @@ -2750,7 +2749,7 @@ sealed class AgentErrorType { @Serializable @SerialName("CMD") class CMD(val cmdErr: CommandErrorType): AgentErrorType() @Serializable @SerialName("CONN") class CONN(val connErr: ConnectionErrorType): AgentErrorType() @Serializable @SerialName("SMP") class SMP(val smpErr: SMPErrorType): AgentErrorType() - @Serializable @SerialName("BROKER") class BROKER(val brokerErr: BrokerErrorType): AgentErrorType() + @Serializable @SerialName("BROKER") class BROKER(val brokerAddress: String, val brokerErr: BrokerErrorType): AgentErrorType() @Serializable @SerialName("AGENT") class AGENT(val agentErr: SMPAgentError): AgentErrorType() @Serializable @SerialName("INTERNAL") class INTERNAL(val internalErr: String): AgentErrorType() } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt index 77588cc149..268a857f7f 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt @@ -88,7 +88,7 @@ fun PreviewCIMetaViewSendFailed() { CIMetaView( chatItem = ChatItem.getSampleData( 1, CIDirection.DirectSnd(), Clock.System.now(), "hello", - status = CIStatus.SndError(AgentErrorType.CMD(CommandErrorType.SYNTAX())) + status = CIStatus.SndError("CMD SYNTAX") ) ) } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt index 077b3f4eb1..afc949ceae 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt @@ -59,7 +59,7 @@ fun ChatItemView( showMsgDeliveryErrorAlert(generalGetString(R.string.message_delivery_error_desc)) } is CIStatus.SndError -> { - showMsgDeliveryErrorAlert(generalGetString(R.string.unknown_error) + ": ${cItem.meta.itemStatus.agentError.string}") + showMsgDeliveryErrorAlert(generalGetString(R.string.unknown_error) + ": ${cItem.meta.itemStatus.agentError}") } else -> {} } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SMPServerView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SMPServerView.kt index 88418f7a90..e6d61332ce 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SMPServerView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SMPServerView.kt @@ -196,5 +196,5 @@ suspend fun testServerConnection(server: ServerCfg, m: ChatModel): Pair, m: ChatModel, onUpd // toList() is important. Otherwise, Compose will not redraw the screen after first update onUpdated(updatedServers.toList()) if (f != null) { - fs[serverHostname(updatedServer)] = f + fs[serverHostname(updatedServer.server)] = f } } } diff --git a/apps/android/app/src/main/res/values-de/strings.xml b/apps/android/app/src/main/res/values-de/strings.xml index 45bc316f49..a1d089af54 100644 --- a/apps/android/app/src/main/res/values-de/strings.xml +++ b/apps/android/app/src/main/res/values-de/strings.xml @@ -61,7 +61,7 @@ Verbindungszeitüberschreitung Verbindungsfehler - Bitte überprüfen Sie Ihre Netzwerkverbindung und versuchen Sie es erneut. + *** Bitte überprüfen Sie Ihre Netzwerkverbindung mit %1$s und versuchen Sie es erneut. Fehler beim Senden der Nachricht Fehler beim Hinzufügen von Mitgliedern Fehler beim Beitritt zur Gruppe diff --git a/apps/android/app/src/main/res/values-ru/strings.xml b/apps/android/app/src/main/res/values-ru/strings.xml index 895e3e2201..0a9f447392 100644 --- a/apps/android/app/src/main/res/values-ru/strings.xml +++ b/apps/android/app/src/main/res/values-ru/strings.xml @@ -61,7 +61,7 @@ Превышено время соединения Ошибка соединения - Пожалуйста, проверьте ваше соединение с сетью и попробуйте еще раз. + Пожалуйста, проверьте ваше соединение с сервером %1$s и попробуйте еще раз. Ошибка при отправке сообщения Ошибка при добавлении членов группы Ошибка при вступлении в группу diff --git a/apps/android/app/src/main/res/values/strings.xml b/apps/android/app/src/main/res/values/strings.xml index a892af2547..ea7196a5e8 100644 --- a/apps/android/app/src/main/res/values/strings.xml +++ b/apps/android/app/src/main/res/values/strings.xml @@ -61,7 +61,7 @@ Connection timeout Connection error - Please check your network connection and try again. + Please check your network connection with %1$s and try again. Error sending message Error adding member(s) Error joining group diff --git a/apps/ios/Shared/Model/SimpleXAPI.swift b/apps/ios/Shared/Model/SimpleXAPI.swift index 19ee4ef6e8..f5a62e7f0b 100644 --- a/apps/ios/Shared/Model/SimpleXAPI.swift +++ b/apps/ios/Shared/Model/SimpleXAPI.swift @@ -603,16 +603,16 @@ func apiReceiveFile(fileId: Int64, inline: Bool) async -> AChatItem? { func networkErrorAlert(_ r: ChatResponse) -> Bool { let am = AlertManager.shared switch r { - case .chatCmdError(.errorAgent(.BROKER(.TIMEOUT))): + case let .chatCmdError(.errorAgent(.BROKER(addr, .TIMEOUT))): am.showAlertMsg( title: "Connection timeout", - message: "Please check your network connection and try again." + message: "Please check your network connection with \(serverHostname(addr)) and try again." ) return true - case .chatCmdError(.errorAgent(.BROKER(.NETWORK))): + case let .chatCmdError(.errorAgent(.BROKER(addr, .NETWORK))): am.showAlertMsg( title: "Connection error", - message: "Please check your network connection and try again." + message: "Please check your network connection with \(serverHostname(addr)) and try again." ) return true default: @@ -1146,7 +1146,7 @@ func processContactSubError(_ contact: Contact, _ chatError: ChatError) { m.updateContact(contact) var err: String switch chatError { - case .errorAgent(agentError: .BROKER(brokerErr: .NETWORK)): err = "network" + case .errorAgent(agentError: .BROKER(_, .NETWORK)): err = "network" case .errorAgent(agentError: .SMP(smpErr: .AUTH)): err = "contact deleted" default: err = String(describing: chatError) } diff --git a/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift b/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift index a101b5fb42..3c980fe0de 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/FramedItemView.swift @@ -67,7 +67,7 @@ struct FramedItemView: View { case .sndErrorAuth: v.onTapGesture { msgDeliveryError("Most likely this contact has deleted the connection with you.") } case let .sndError(agentError): - v.onTapGesture { msgDeliveryError("Unexpected error: \(String(describing: agentError))") } + v.onTapGesture { msgDeliveryError("Unexpected error: \(agentError)") } default: v } } diff --git a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift index f01e31dab7..9ab52ee71c 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListNavLink.swift @@ -402,10 +402,10 @@ struct ErrorAlert { func getErrorAlert(_ error: Error, _ title: LocalizedStringKey) -> ErrorAlert { switch error as? ChatResponse { - case .chatCmdError(.errorAgent(.BROKER(.TIMEOUT))): - return ErrorAlert(title: "Connection timeout", message: "Please check your network connection and try again.") - case .chatCmdError(.errorAgent(.BROKER(.NETWORK))): - return ErrorAlert(title: "Connection error", message: "Please check your network connection and try again.") + case let .chatCmdError(.errorAgent(.BROKER(addr, .TIMEOUT))): + return ErrorAlert(title: "Connection timeout", message: "Please check your network connection with \(serverHostname(addr)) and try again.") + case let .chatCmdError(.errorAgent(.BROKER(addr, .NETWORK))): + return ErrorAlert(title: "Connection error", message: "Please check your network connection with \(serverHostname(addr)) and try again.") default: return ErrorAlert(title: title, message: "Error: \(responseError(error))") } diff --git a/apps/ios/Shared/Views/UserSettings/SMPServerView.swift b/apps/ios/Shared/Views/UserSettings/SMPServerView.swift index 47ed5a6223..8aa2e92909 100644 --- a/apps/ios/Shared/Views/UserSettings/SMPServerView.swift +++ b/apps/ios/Shared/Views/UserSettings/SMPServerView.swift @@ -155,8 +155,8 @@ func testServerConnection(server: Binding) async -> SMPTestFailure? { } } -func serverHostname(_ srv: ServerCfg) -> String { - parseServerAddress(srv.server)?.hostnames.first ?? srv.server +func serverHostname(_ srv: String) -> String { + parseServerAddress(srv)?.hostnames.first ?? srv } struct SMPServerView_Previews: PreviewProvider { diff --git a/apps/ios/Shared/Views/UserSettings/SMPServersView.swift b/apps/ios/Shared/Views/UserSettings/SMPServersView.swift index 8b03bf415c..42615ed69f 100644 --- a/apps/ios/Shared/Views/UserSettings/SMPServersView.swift +++ b/apps/ios/Shared/Views/UserSettings/SMPServersView.swift @@ -222,7 +222,7 @@ struct SMPServersView: View { for i in 0..