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 16734f669f..93ef19aeeb 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 @@ -3873,12 +3873,11 @@ sealed class UserServersError { @Serializable @SerialName("duplicateServer") data class DuplicateServer(val protocol: ServerProtocol, val duplicateServer: String, val duplicateHost: String): UserServersError() val globalError: String? - get() = when (this) { - is NoServers -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError }) - is StorageMissing -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError }) - is ProxyMissing -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError }) - else -> null + get() = when (this.protocol_) { + ServerProtocol.SMP -> globalSMPError + ServerProtocol.XFTP -> globalXFTPError } + private val protocol_: ServerProtocol get() = when (this) { is NoServers -> this.protocol @@ -3886,6 +3885,7 @@ sealed class UserServersError { is ProxyMissing -> this.protocol is DuplicateServer -> this.protocol } + val globalSMPError: String? get() = if (this.protocol_ == ServerProtocol.SMP) { when (this) { @@ -3903,6 +3903,7 @@ sealed class UserServersError { } else { null } + val globalXFTPError: String? get() = if (this.protocol_ == ServerProtocol.XFTP) { when (this) { @@ -3924,16 +3925,6 @@ sealed class UserServersError { private fun userStr(user: UserRef): String { return String.format(generalGetString(MR.strings.for_chat_profile), user.localDisplayName) } - - private fun ServerProtocol.toGlobalError( - smpHandler: () -> String?, - xftpHandler: () -> String? - ): String? { - return when (this) { - ServerProtocol.SMP -> smpHandler() - ServerProtocol.XFTP -> xftpHandler() - } - } } @Serializable 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 52301c9577..518a670615 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 @@ -52,7 +52,7 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) { val proxyPort = remember { derivedStateOf { appPrefs.networkProxy.state.value.port } } ModalView( close = { - if (currUserServers.value == userServers.value) { + if (!serversCanBeSaved(currUserServers.value, userServers.value, serverErrors.value)) { close() } else { showUnsavedChangesAlert( @@ -227,7 +227,7 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) { } } - val saveDisabled = userServers.value == currUserServers.value + val saveDisabled = !serversCanBeSaved(currUserServers.value, userServers.value, serverErrors.value) SectionItemView( { scope.launch { saveServers(rhId = currentRemoteHost?.remoteHostId, currUserServers, userServers) } }, 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 b7f97574ce..2574604356 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 @@ -152,16 +152,23 @@ fun OperatorViewLayout( } UseOperatorToggle(currUserServers = currUserServers, userServers = userServers, serverErrors = serverErrors, operatorIndex = operatorIndex, rhId = rhId) } - val footerText = when (val c = operator.conditionsAcceptance) { - is ConditionsAcceptance.Accepted -> if (c.acceptedAt != null) { - String.format(generalGetString(MR.strings.operator_conditions_accepted_on), localTimestamp(c.acceptedAt)) - } else null - is ConditionsAcceptance.Required -> if (operator.enabled && c.deadline != null) { - String.format(generalGetString(MR.strings.operator_conditions_accepted_after), localTimestamp(c.deadline)) - } else null - } - if (footerText != null) { - SectionTextFooter(footerText) + val serversErr = globalServersError(serverErrors.value) + if (serversErr != null) { + SectionCustomFooter { + ServerErrorsView(serversErr) + } + } else { + val footerText = when (val c = operator.conditionsAcceptance) { + is ConditionsAcceptance.Accepted -> if (c.acceptedAt != null) { + String.format(generalGetString(MR.strings.operator_conditions_accepted_on), localTimestamp(c.acceptedAt)) + } else null + is ConditionsAcceptance.Required -> if (operator.enabled && c.deadline != null) { + String.format(generalGetString(MR.strings.operator_conditions_accepted_after), localTimestamp(c.deadline)) + } else null + } + if (footerText != null) { + SectionTextFooter(footerText) + } } if (operator.enabled) { @@ -216,10 +223,10 @@ fun OperatorViewLayout( } } - val smpErrors = globalSMPServersError(serverErrors.value) - if (smpErrors != null) { + val smpErr = globalSMPServersError(serverErrors.value) + if (smpErr != null) { SectionCustomFooter { - ServerErrorsView(smpErrors) + ServerErrorsView(smpErr) } } } @@ -239,10 +246,10 @@ fun OperatorViewLayout( } } } - val smpErrors = globalSMPServersError(serverErrors.value) - if (smpErrors != null) { + val smpErr = globalSMPServersError(serverErrors.value) + if (smpErr != null) { SectionCustomFooter { - ServerErrorsView(smpErrors) + ServerErrorsView(smpErr) } } else { SectionTextFooter( @@ -302,10 +309,10 @@ fun OperatorViewLayout( ) } } - val xftpErrors = globalXFTPServersError(serverErrors.value) - if (xftpErrors != null) { + val xftpErr = globalXFTPServersError(serverErrors.value) + if (xftpErr != null) { SectionCustomFooter { - ServerErrorsView(xftpErrors) + ServerErrorsView(xftpErr) } } } @@ -325,10 +332,10 @@ fun OperatorViewLayout( } } } - val xftpErrors = globalXFTPServersError(serverErrors.value) - if (xftpErrors != null) { + val xftpErr = globalXFTPServersError(serverErrors.value) + if (xftpErr != null) { SectionCustomFooter { - ServerErrorsView(xftpErrors) + ServerErrorsView(xftpErr) } } else { SectionTextFooter( @@ -359,24 +366,6 @@ fun OperatorViewLayout( } } } - val xftpErrors = globalXFTPServersError(serverErrors.value) - if (xftpErrors != null) { - SectionCustomFooter { - ServerErrorsView(xftpErrors) - } - } else { - SectionTextFooter( - remember(currentUser?.displayName) { - buildAnnotatedString { - append(generalGetString(MR.strings.xftp_servers_per_user) + " ") - withStyle(SpanStyle(fontWeight = FontWeight.Bold)) { - append(currentUser?.displayName ?: "") - } - append(".") - } - } - ) - } } SectionDividerSpaced() 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 61feaf7498..facbd89eab 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 @@ -87,10 +87,10 @@ fun YourServersViewLayout( } } } - val smpErrors = globalSMPServersError(serverErrors.value) - if (smpErrors != null) { + val smpErr = globalSMPServersError(serverErrors.value) + if (smpErr != null) { SectionCustomFooter { - ServerErrorsView(smpErrors) + ServerErrorsView(smpErr) } } else { SectionTextFooter( @@ -121,10 +121,10 @@ fun YourServersViewLayout( } } } - val xftpErrors = globalXFTPServersError(serverErrors.value) - if (xftpErrors != null) { + val xftpErr = globalXFTPServersError(serverErrors.value) + if (xftpErr != null) { SectionCustomFooter { - ServerErrorsView(xftpErrors) + ServerErrorsView(xftpErr) } } else { SectionTextFooter( @@ -158,6 +158,12 @@ fun YourServersViewLayout( iconColor = if (testing.value) MaterialTheme.colors.secondary else MaterialTheme.colors.primary ) } + val serversErr = globalServersError(serverErrors.value) + if (serversErr != null) { + SectionCustomFooter { + ServerErrorsView(serversErr) + } + } SectionDividerSpaced(maxTopPadding = false, maxBottomPadding = false) SectionView {