diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NetworkAndServers.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NetworkAndServers.kt index 08d8ddf8d6..f4d42022f0 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NetworkAndServers.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NetworkAndServers.kt @@ -50,9 +50,15 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) { val currUserServers = remember { stateGetOrPut("currUserServers") { emptyList() } } val userServers = remember { stateGetOrPut("userServers") { emptyList() } } val serverErrors = remember { stateGetOrPut("serverErrors") { emptyList() } } - val scope = rememberCoroutineScope() + LaunchedEffect(userServers) { + snapshotFlow { userServers.value } + .collect { updatedServers -> + validateServers(rhId = currentRemoteHost?.remoteHostId, userServersToValidate = updatedServers, serverErrors = serverErrors) + } + } + val proxyPort = remember { derivedStateOf { appPrefs.networkProxy.state.value.port } } ModalView( close = { @@ -819,11 +825,9 @@ fun updateOperatorsConditionsAcceptance(usvs: MutableState>, + userServersToValidate: List, serverErrors: MutableState> ) { - val userServersToValidate = userServers.value - try { val errors = chatController.validateServers(rhId, userServersToValidate) ?: return serverErrors.value = errors diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NewServerView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NewServerView.kt index 566600f7bf..a2ff6fdf2a 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NewServerView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/NewServerView.kt @@ -22,6 +22,13 @@ fun ModalData.NewServerView( val scope = rememberCoroutineScope() val newServer = remember { mutableStateOf(UserServer.empty) } + LaunchedEffect(userServers) { + snapshotFlow { userServers.value } + .collect { updatedServers -> + validateServers(rhId = rhId, userServersToValidate = updatedServers, serverErrors = serverErrors) + } + } + ModalView(close = { addServer( scope, @@ -122,7 +129,6 @@ fun addServer( userServers.value = updatedUserServers close() - scope.launch { validateServers(rhId, userServers, serverErrors) } matchingOperator?.let { op -> AlertManager.shared.showAlertMsg( title = generalGetString(MR.strings.operator_server_alert_title), diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/OperatorView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/OperatorView.kt index 3c40f62b7b..9ea1a18e6c 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/OperatorView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/OperatorView.kt @@ -44,7 +44,13 @@ fun ModalData.OperatorView( val testing = remember { mutableStateOf(false) } val operator = remember { userServers.value[operatorIndex].operator_ } val currentUser = remember { chatModel.currentUser }.value - val scope = rememberCoroutineScope() + + LaunchedEffect(userServers) { + snapshotFlow { userServers.value } + .collect { updatedServers -> + validateServers(rhId = rhId, userServersToValidate = updatedServers, serverErrors = serverErrors) + } + } Box { ColumnWithScrollBar(Modifier.alpha(if (testing.value) 0.6f else 1f)) { @@ -55,7 +61,7 @@ fun ModalData.OperatorView( serverErrors, operatorIndex, navigateToProtocolView = { serverIndex, server, protocol -> - navigateToProtocolView(scope, userServers, serverErrors, operatorIndex, rhId, serverIndex, server, protocol) + navigateToProtocolView(userServers, serverErrors, operatorIndex, rhId, serverIndex, server, protocol) }, currentUser, rhId, @@ -70,7 +76,6 @@ fun ModalData.OperatorView( } fun navigateToProtocolView( - scope: CoroutineScope, userServers: MutableState>, serverErrors: MutableState>, operatorIndex: Int, @@ -93,7 +98,6 @@ fun navigateToProtocolView( deleteXFTPServer(userServers, operatorIndex, serverIndex) } close() - scope.launch { validateServers(rhId, userServers, serverErrors) } }, onUpdate = { updatedServer -> userServers.value = userServers.value.toMutableList().apply { @@ -195,9 +199,6 @@ fun OperatorViewLayout( ) ) } - scope.launch { - validateServers(rhId, userServers, serverErrors) - } } ) } @@ -218,9 +219,6 @@ fun OperatorViewLayout( ) ) } - scope.launch { - validateServers(rhId, userServers, serverErrors) - } } ) } @@ -305,9 +303,6 @@ fun OperatorViewLayout( ) ) } - scope.launch { - validateServers(rhId, userServers, serverErrors) - } } ) } @@ -444,7 +439,6 @@ private fun UseOperatorToggle( when (val conditionsAcceptance = operator?.conditionsAcceptance) { is ConditionsAcceptance.Accepted -> { changeOperatorEnabled(userServers, operatorIndex, true) - scope.launch { validateServers(rhId, userServers, serverErrors) } } is ConditionsAcceptance.Required -> { @@ -461,7 +455,6 @@ private fun UseOperatorToggle( } } else { changeOperatorEnabled(userServers, operatorIndex, true) - scope.launch { validateServers(rhId, userServers, serverErrors) } } } @@ -469,7 +462,6 @@ private fun UseOperatorToggle( } } else { changeOperatorEnabled(userServers, operatorIndex, false) - scope.launch { validateServers(rhId, userServers, serverErrors) } } }, ) @@ -498,7 +490,6 @@ private fun SingleOperatorUsageConditionsView( updateOperatorsConditionsAcceptance(currUserServers, r.serverOperators) updateOperatorsConditionsAcceptance(userServers, r.serverOperators) changeOperatorEnabled(userServers, operatorIndex, true) - validateServers(rhId, userServers, serverErrors) close() } catch (ex: Exception) { Log.e(TAG, ex.stackTraceToString()) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServerView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServerView.kt index e3a1c85a5a..42a020c56e 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServerView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServerView.kt @@ -45,6 +45,13 @@ fun ProtocolServerView( val scope = rememberCoroutineScope() val draftServer = remember { mutableStateOf(server) } + LaunchedEffect(userServers) { + snapshotFlow { userServers.value } + .collect { updatedServers -> + validateServers(rhId = rhId, userServersToValidate = updatedServers, serverErrors = serverErrors) + } + } + ModalView( close = { scope.launch { @@ -70,7 +77,6 @@ fun ProtocolServerView( } else { onUpdate(draftServer.value) close() - validateServers(rhId, userServers, serverErrors) } } else { close() diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServersView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServersView.kt index 45bc92ae2e..c0659b80aa 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServersView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/usersettings/networkAndServers/ProtocolServersView.kt @@ -46,7 +46,7 @@ fun ModalData.YourServersView( serverErrors, operatorIndex, navigateToProtocolView = { serverIndex, server, protocol -> - navigateToProtocolView(scope, userServers, serverErrors, operatorIndex, rhId, serverIndex, server, protocol) + navigateToProtocolView(userServers, serverErrors, operatorIndex, rhId, serverIndex, server, protocol) }, currentUser, rhId,