From dcf9ce30116cadb871afae09fcaf4ef8dec3135c Mon Sep 17 00:00:00 2001 From: Narasimha-sc <166327228+Narasimha-sc@users.noreply.github.com> Date: Tue, 20 Oct 2026 08:37:55 +0000 Subject: [PATCH] android: keep the error alert for the network info command, remove comments, fix spec line references --- apps/ios/Shared/Model/NetworkObserver.swift | 1 - apps/ios/spec/api.md | 4 ++-- apps/ios/spec/architecture.md | 6 +++--- .../kotlin/chat/simplex/common/helpers/NetworkObserver.kt | 2 -- .../kotlin/chat/simplex/common/model/SimpleXAPI.kt | 6 ++---- apps/multiplatform/spec/api.md | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apps/ios/Shared/Model/NetworkObserver.swift b/apps/ios/Shared/Model/NetworkObserver.swift index 01116fc548..1302f8a50a 100644 --- a/apps/ios/Shared/Model/NetworkObserver.swift +++ b/apps/ios/Shared/Model/NetworkObserver.swift @@ -64,7 +64,6 @@ class NetworkObserver { self.monitorLock.sync { guard let ctrl = currentChatCtrl() else { return } do { - // the controller is passed, so that resetting it while the report is sent is not a crash try apiSetNetworkInfo(info, ctrl: ctrl) } catch let err { logger.error("setNetworkInfo error: \(responseError(err))") diff --git a/apps/ios/spec/api.md b/apps/ios/spec/api.md index b835ab4dd8..bfb5745fd1 100644 --- a/apps/ios/spec/api.md +++ b/apps/ios/spec/api.md @@ -35,7 +35,7 @@ The iOS app communicates with the Haskell core exclusively through a command/res - [`Shared/Model/AppAPITypes.swift`](../Shared/Model/AppAPITypes.swift) -- `ChatCommand` ([L15](../Shared/Model/AppAPITypes.swift#L15)), `ChatResponse0` ([L657](../Shared/Model/AppAPITypes.swift#L657)), `ChatResponse1` ([L779](../Shared/Model/AppAPITypes.swift#L779)), `ChatResponse2` ([L919](../Shared/Model/AppAPITypes.swift#L919)), `ChatEvent` ([L1069](../Shared/Model/AppAPITypes.swift#L1069)) enums - [`SimpleXChat/APITypes.swift`](../SimpleXChat/APITypes.swift) -- `APIResult` ([L27](../SimpleXChat/APITypes.swift#L27)), `ChatAPIResult` ([L65](../SimpleXChat/APITypes.swift#L65)), `ChatError` ([L699](../SimpleXChat/APITypes.swift#L699)) - [`Shared/Model/SimpleXAPI.swift`](../Shared/Model/SimpleXAPI.swift) -- FFI bridge functions (`chatSendCmd` [L121](../Shared/Model/SimpleXAPI.swift#L121), `chatRecvMsg` [L237](../Shared/Model/SimpleXAPI.swift#L237)) -- [`SimpleXChat/API.swift`](../SimpleXChat/API.swift) -- Low-level FFI (`sendSimpleXCmd` [L119](../SimpleXChat/API.swift#L119), `recvSimpleXMsg` [L141](../SimpleXChat/API.swift#L141)) +- [`SimpleXChat/API.swift`](../SimpleXChat/API.swift) -- Low-level FFI (`sendSimpleXCmd` [L124](../SimpleXChat/API.swift#L124), `recvSimpleXMsg` [L146](../SimpleXChat/API.swift#L146)) - `SimpleXChat/ChatTypes.swift` -- Data types used in commands/responses (User, Contact, GroupInfo, ChatItem, etc.) - `../../src/Simplex/Chat/Controller.hs` -- Haskell controller (function `chat_send_cmd_retry`, `chat_recv_msg_wait`) @@ -543,7 +543,7 @@ func chatApiSendCmdWithRetry( // SimpleXAPI.swift L127 ```swift // Direct C FFI call -- serializes cmd.cmdString, calls chat_send_cmd_retry, decodes response -public func sendSimpleXCmd( // API.swift L119 +public func sendSimpleXCmd( // API.swift L124 _ cmd: ChatCmdProtocol, _ ctrl: chat_ctrl?, retryNum: Int32 = 0 diff --git a/apps/ios/spec/architecture.md b/apps/ios/spec/architecture.md index ec75cdb870..9537349bff 100644 --- a/apps/ios/spec/architecture.md +++ b/apps/ios/spec/architecture.md @@ -112,14 +112,14 @@ func chatApiSendCmd(_ cmd: ChatCommand, bgTask: Bool = true, // Low-level FFI call -- serializes command to string, calls chat_send_cmd_retry, decodes JSON func sendSimpleXCmd(_ cmd: ChatCmdProtocol, _ ctrl: chat_ctrl?, - retryNum: Int32 = 0) -> APIResult // SimpleXChat/API.swift L119 + retryNum: Int32 = 0) -> APIResult // SimpleXChat/API.swift L124 ``` ### Data Flow 1. Swift constructs a `ChatCommand` enum value (e.g., `.apiSendMessages(type:id:scope:live:ttl:composedMessages:)`) 2. [`ChatCommand.cmdString`](../Shared/Model/AppAPITypes.swift#L15) serializes it to a command string (e.g., `"/_send @1 json {...}"`) -3. [`sendSimpleXCmd`](../SimpleXChat/API.swift#L119) passes the string to `chat_send_cmd_retry` via C FFI +3. [`sendSimpleXCmd`](../SimpleXChat/API.swift#L124) passes the string to `chat_send_cmd_retry` via C FFI 4. Haskell core processes the command, returns JSON response string 5. Swift decodes JSON into [`APIResult`](../SimpleXChat/APITypes.swift#L27) where `R: ChatAPIResult` 6. Result is either `.result(R)`, `.error(ChatError)`, or `.invalid(type, json)` @@ -323,7 +323,7 @@ Chat relays are SMP servers that forward messages to channel subscribers. They a | App delegate | [`Shared/AppDelegate.swift`](../Shared/AppDelegate.swift#L15) | L15 | | Root view | [`Shared/ContentView.swift`](../Shared/ContentView.swift#L24) | L24 | | FFI bridge | [`Shared/Model/SimpleXAPI.swift`](../Shared/Model/SimpleXAPI.swift#L93) | L93 | -| Low-level FFI | [`SimpleXChat/API.swift`](../SimpleXChat/API.swift#L119) | L119 | +| Low-level FFI | [`SimpleXChat/API.swift`](../SimpleXChat/API.swift#L124) | L124 | | App state | [`Shared/Model/ChatModel.swift`](../Shared/Model/ChatModel.swift#L337) | L337 | | API types | [`Shared/Model/AppAPITypes.swift`](../Shared/Model/AppAPITypes.swift#L15) | L15 | | Shared types | [`SimpleXChat/APITypes.swift`](../SimpleXChat/APITypes.swift#L27) | L27 | diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/helpers/NetworkObserver.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/helpers/NetworkObserver.kt index 7e7f888013..b8ed71207f 100644 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/helpers/NetworkObserver.kt +++ b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/helpers/NetworkObserver.kt @@ -78,7 +78,6 @@ class NetworkObserver { noNetworkJob.cancel() if (info.online) { withBGApi { - // the controller is read once and passed, so that replacing it between the two does not fail the command val ctrl = controller.currentCtrl() if (ctrl != null && controller.apiSetNetworkInfo(info, ctrl)) { chatModel.networkInfo.value = info @@ -87,7 +86,6 @@ class NetworkObserver { } else { noNetworkJob = withBGApi { delay(3000) - // the controller is read once and passed, so that replacing it between the two does not fail the command val ctrl = controller.currentCtrl() if (ctrl != null && controller.apiSetNetworkInfo(info, ctrl)) { chatModel.networkInfo.value = info 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 f970c79b26..d48a7c1574 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 @@ -536,7 +536,7 @@ class AppPreferences { private const val MESSAGE_TIMEOUT: Int = 300_000_000 object ChatController { - @Volatile private var chatCtrl: ChatCtrl? = -1 + private var chatCtrl: ChatCtrl? = -1 // Spec: spec/state.md#appPrefs val appPrefs: AppPreferences by lazy { AppPreferences() } @@ -551,7 +551,6 @@ object ChatController { fun getChatCtrl(): ChatCtrl? = chatCtrl - // read once, so that the controller that is reset between the checks is not used fun currentCtrl(): ChatCtrl? = chatCtrl?.takeIf { it != -1L } fun setChatCtrl(ctrl: ChatCtrl?) { @@ -1534,9 +1533,8 @@ object ChatController { return false } - // the network info is reported automatically, and again on the next event, so a failure is not alerted about suspend fun apiSetNetworkInfo(networkInfo: UserNetworkInfo, ctrl: ChatCtrl): Boolean = - sendCmd(null, CC.APISetNetworkInfo(networkInfo), ctrl).ok + sendCommandOkResp(null, CC.APISetNetworkInfo(networkInfo), ctrl) suspend fun apiSetMemberSettings(rh: Long?, groupId: Long, groupMemberId: Long, memberSettings: GroupMemberSettings): Boolean = sendCommandOkResp(rh, CC.ApiSetMemberSettings(groupId, groupMemberId, memberSettings)) diff --git a/apps/multiplatform/spec/api.md b/apps/multiplatform/spec/api.md index 18eda00df3..946fccd457 100644 --- a/apps/multiplatform/spec/api.md +++ b/apps/multiplatform/spec/api.md @@ -234,7 +234,7 @@ All functions below are `suspend fun` members of `ChatController` ([SimpleXAPI.k | Command | Parameters | Description | Line | |---------|-----------|-------------|------| | `apiSetNetworkConfig` | `cfg: NetCfg, showAlertOnError: Boolean, ctrl: ChatCtrl?` | Apply network configuration (SOCKS proxy, timeouts, etc.) | [L1313](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L1313) | -| `apiSetNetworkInfo` | `networkInfo: UserNetworkInfo, ctrl: ChatCtrl` | Update network reachability information | [L1398](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L1398) | +| `apiSetNetworkInfo` | `networkInfo: UserNetworkInfo, ctrl: ChatCtrl` | Update network reachability information | [L1536](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L1536) | | `apiSetSettings` | `rh: Long?, type: ChatType, id: Long, settings: ChatSettings` | Update per-chat settings (notifications, favorites) | [L1333](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L1333) | | `apiStorageEncryption` | `currentKey: String, newKey: String` | Change the database encryption passphrase | [L999](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L999) | | `testStorageEncryption` | `key: String, ctrl: ChatCtrl?` | Verify a database encryption key is correct | [L1006](../common/src/commonMain/kotlin/chat/simplex/common/model/SimpleXAPI.kt#L1006) |