mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-10 01:21:52 +00:00
test servers button
This commit is contained in:
+54
@@ -69,6 +69,7 @@ fun OperatorViewLayout(
|
||||
val operator by remember { derivedStateOf { userServers.value[operatorIndex].operator_ } }
|
||||
val scope = rememberCoroutineScope()
|
||||
val duplicateHosts = findDuplicateHosts(serverErrors.value)
|
||||
val testing = remember { mutableStateOf(false) }
|
||||
|
||||
Column {
|
||||
SectionView(generalGetString(MR.strings.operator).uppercase()) {
|
||||
@@ -277,6 +278,59 @@ fun OperatorViewLayout(
|
||||
}
|
||||
}
|
||||
|
||||
if (userServers.value[operatorIndex].xftpServers.any { !it.preset && !it.deleted}) {
|
||||
SectionDividerSpaced()
|
||||
SectionView(generalGetString(MR.strings.operator_added_xftp_servers).uppercase()) {
|
||||
userServers.value[operatorIndex].xftpServers.forEach { server ->
|
||||
if (server.deleted || server.preset) return@forEach
|
||||
SectionItemView {
|
||||
ProtocolServerView(
|
||||
srv = server,
|
||||
serverProtocol = ServerProtocol.XFTP,
|
||||
duplicateHosts = duplicateHosts
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
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()
|
||||
TestServersButton(
|
||||
testing = testing,
|
||||
smpServers = userServers.value[operatorIndex].smpServers,
|
||||
xftpServers = userServers.value[operatorIndex].xftpServers,
|
||||
) { p, l ->
|
||||
when (p) {
|
||||
ServerProtocol.XFTP -> userServers.value = userServers.value.toMutableList().apply {
|
||||
this[operatorIndex] = this[operatorIndex].copy(
|
||||
xftpServers = l
|
||||
)
|
||||
}
|
||||
ServerProtocol.SMP -> userServers.value = userServers.value.toMutableList().apply {
|
||||
this[operatorIndex] = this[operatorIndex].copy(
|
||||
smpServers = l
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+25
-2
@@ -22,10 +22,10 @@ import androidx.compose.ui.unit.dp
|
||||
import chat.simplex.common.model.ServerAddress.Companion.parseServerAddress
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.common.model.*
|
||||
import chat.simplex.common.platform.ColumnWithScrollBar
|
||||
import chat.simplex.common.platform.appPlatform
|
||||
import chat.simplex.common.platform.*
|
||||
import chat.simplex.common.views.usersettings.SettingsActionItem
|
||||
import chat.simplex.res.MR
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun ModalData.ProtocolServersView(m: ChatModel, rhId: Long?, serverProtocol: ServerProtocol, close: () -> Unit) {
|
||||
@@ -333,6 +333,29 @@ fun YourServersViewLayout(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun TestServersButton(
|
||||
smpServers: List<UserServer>,
|
||||
xftpServers: List<UserServer>,
|
||||
testing: MutableState<Boolean>,
|
||||
onUpdate: (ServerProtocol, List<UserServer>) -> Unit
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val disabled = derivedStateOf { (smpServers.none { it.enabled } && xftpServers.none { it.enabled }) || testing.value }
|
||||
|
||||
SectionItemView(
|
||||
{
|
||||
scope.launch {
|
||||
testServers(testing, smpServers, chatModel) { onUpdate(ServerProtocol.SMP, it) }
|
||||
testServers(testing, xftpServers, chatModel) { onUpdate(ServerProtocol.XFTP, it) }
|
||||
}
|
||||
},
|
||||
disabled = disabled.value
|
||||
) {
|
||||
Text(stringResource(MR.strings.smp_servers_test_servers), color = if (!disabled.value) MaterialTheme.colors.onBackground else MaterialTheme.colors.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
fun showAddServerDialog(
|
||||
userServers: MutableState<List<UserOperatorServers>>,
|
||||
serverErrors: MutableState<List<UserServersError>>,
|
||||
|
||||
@@ -1708,6 +1708,7 @@
|
||||
<string name="operator_use_for_files">Use for files</string>
|
||||
<string name="operator_use_for_sending">For sending</string>
|
||||
<string name="xftp_servers_per_user">The servers for new files of your current chat profile</string>
|
||||
<string name="operator_added_xftp_servers">Added media & file servers</string>
|
||||
|
||||
<!-- AdvancedNetworkSettings.kt -->
|
||||
<string name="network_option_tcp_connection">TCP connection</string>
|
||||
|
||||
Reference in New Issue
Block a user