From d4ac1c0cf2a21c7a1f38582cc84a5fe5ccbd9b65 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 26 Nov 2023 23:23:37 +0000 Subject: [PATCH] core, ui: add remote host/controller stop reasons to events (#3472) --- apps/ios/SimpleXChat/APITypes.swift | 9 ++++++++- .../kotlin/chat/simplex/common/model/ChatModel.kt | 8 ++++++++ .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 11 +++++++++-- src/Simplex/Chat/Controller.hs | 10 +++++----- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/apps/ios/SimpleXChat/APITypes.swift b/apps/ios/SimpleXChat/APITypes.swift index ad0e5ee10..9128f67f2 100644 --- a/apps/ios/SimpleXChat/APITypes.swift +++ b/apps/ios/SimpleXChat/APITypes.swift @@ -613,7 +613,7 @@ public enum ChatResponse: Decodable, Error { case remoteCtrlConnecting(remoteCtrl_: RemoteCtrlInfo?, ctrlAppInfo: CtrlAppInfo, appVersion: String) case remoteCtrlSessionCode(remoteCtrl_: RemoteCtrlInfo?, sessionCode: String) case remoteCtrlConnected(remoteCtrl: RemoteCtrlInfo) - case remoteCtrlStopped + case remoteCtrlStopped(rcsState: RemoteCtrlSessionState, rcStopReason: RemoteCtrlStopReason) // misc case versionInfo(versionInfo: CoreVersionInfo, chatMigrations: [UpMigration], agentMigrations: [UpMigration]) case cmdOk(user: UserRef?) @@ -1552,6 +1552,13 @@ public enum RemoteCtrlSessionState: Decodable { case connected(sessionCode: String) } +public enum RemoteCtrlStopReason: Decodable { + case discoveryFailed(chatError: ChatError) + case connectionFailed(chatError: ChatError) + case setupFailed(chatError: ChatError) + case disconnected +} + public struct CtrlAppInfo: Decodable { public var appVersionRange: AppVersionRange public var deviceName: String diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt index 76c2f39fb..e0d17d843 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/ChatModel.kt @@ -2945,6 +2945,14 @@ sealed class RemoteCtrlSessionState { @Serializable @SerialName("connected") data class Connected(val sessionCode: String): RemoteCtrlSessionState() } +@Serializable +sealed class RemoteCtrlStopReason { + @Serializable @SerialName("discoveryFailed") class DiscoveryFailed(val chatError: ChatError): RemoteCtrlStopReason() + @Serializable @SerialName("connectionFailed") class ConnectionFailed(val chatError: ChatError): RemoteCtrlStopReason() + @Serializable @SerialName("setupFailed") class SetupFailed(val chatError: ChatError): RemoteCtrlStopReason() + @Serializable @SerialName("disconnected") object Disconnected: RemoteCtrlStopReason() +} + sealed class UIRemoteCtrlSessionState { object Starting: UIRemoteCtrlSessionState() object Searching: UIRemoteCtrlSessionState() diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt index 727e0d2a3..83ae90cb2 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt @@ -3581,6 +3581,13 @@ sealed class RemoteHostSessionState { @Serializable @SerialName("connected") data class Connected(val sessionCode: String): RemoteHostSessionState() } +@Serializable +sealed class RemoteHostStopReason { + @Serializable @SerialName("connectionFailed") data class ConnectionFailed(val chatError: ChatError): RemoteHostStopReason() + @Serializable @SerialName("crashed") data class Crashed(val chatError: ChatError): RemoteHostStopReason() + @Serializable @SerialName("disconnected") object Disconnected: RemoteHostStopReason() +} + val json = Json { prettyPrint = true ignoreUnknownKeys = true @@ -3804,7 +3811,7 @@ sealed class CR { @Serializable @SerialName("remoteHostSessionCode") class RemoteHostSessionCode(val remoteHost_: RemoteHostInfo?, val sessionCode: String): CR() @Serializable @SerialName("newRemoteHost") class NewRemoteHost(val remoteHost: RemoteHostInfo): CR() @Serializable @SerialName("remoteHostConnected") class RemoteHostConnected(val remoteHost: RemoteHostInfo): CR() - @Serializable @SerialName("remoteHostStopped") class RemoteHostStopped(val remoteHostId_: Long?): CR() + @Serializable @SerialName("remoteHostStopped") class RemoteHostStopped(val remoteHostId_: Long?, val rhsState: RemoteHostSessionState, val rhStopReason: RemoteHostStopReason): CR() @Serializable @SerialName("remoteFileStored") class RemoteFileStored(val remoteHostId: Long, val remoteFileSource: CryptoFile): CR() // remote events (mobile) @Serializable @SerialName("remoteCtrlList") class RemoteCtrlList(val remoteCtrls: List): CR() @@ -3812,7 +3819,7 @@ sealed class CR { @Serializable @SerialName("remoteCtrlConnecting") class RemoteCtrlConnecting(val remoteCtrl_: RemoteCtrlInfo?, val ctrlAppInfo: CtrlAppInfo, val appVersion: String): CR() @Serializable @SerialName("remoteCtrlSessionCode") class RemoteCtrlSessionCode(val remoteCtrl_: RemoteCtrlInfo?, val sessionCode: String): CR() @Serializable @SerialName("remoteCtrlConnected") class RemoteCtrlConnected(val remoteCtrl: RemoteCtrlInfo): CR() - @Serializable @SerialName("remoteCtrlStopped") class RemoteCtrlStopped(): CR() + @Serializable @SerialName("remoteCtrlStopped") class RemoteCtrlStopped(val rcsState: RemoteCtrlSessionState, val rcStopReason: RemoteCtrlStopReason): CR() @Serializable @SerialName("versionInfo") class VersionInfo(val versionInfo: CoreVersionInfo, val chatMigrations: List, val agentMigrations: List): CR() @Serializable @SerialName("cmdOk") class CmdOk(val user: UserRef?): CR() @Serializable @SerialName("chatCmdError") class ChatCmdError(val user_: UserRef?, val chatError: ChatError): CR() diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 32f58b54b..cae17e24a 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -1084,8 +1084,8 @@ data RemoteHostError deriving (Show, Exception) data RemoteHostStopReason - = RHSRConnectionFailed ChatError - | RHSRCrashed ChatError + = RHSRConnectionFailed {chatError :: ChatError} + | RHSRCrashed {chatError :: ChatError} | RHSRDisconnected deriving (Show, Exception) @@ -1106,9 +1106,9 @@ data RemoteCtrlError deriving (Show, Exception) data RemoteCtrlStopReason - = RCSRDiscoveryFailed ChatError - | RCSRConnectionFailed ChatError - | RCSRSetupFailed ChatError + = RCSRDiscoveryFailed {chatError :: ChatError} + | RCSRConnectionFailed {chatError :: ChatError} + | RCSRSetupFailed {chatError :: ChatError} | RCSRDisconnected deriving (Show, Exception)