diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt
index 2cc3243a7..ec9cc18c0 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/RelayStatusRow.kt
@@ -33,6 +33,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
+import androidx.compose.ui.res.stringResource
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.service.countToHumanReadable
import com.vitorpamplona.amethyst.service.countToHumanReadableBytes
@@ -43,6 +44,7 @@ import com.vitorpamplona.amethyst.ui.theme.HalfStartPadding
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
import com.vitorpamplona.amethyst.ui.theme.allGoodColor
import com.vitorpamplona.amethyst.ui.theme.placeholderText
+import com.vitorpamplona.amethyst.ui.theme.redColorOnSecondSurface
import com.vitorpamplona.amethyst.ui.theme.warningColor
@Composable
@@ -126,18 +128,22 @@ fun RelayStatusRow(
onLongPress = {
accountViewModel.toastManager.toast(
R.string.errors,
- R.string.errors_description,
+ R.string.connection_success_rate_description,
)
},
)
},
) {
+ val successRate = ((item.relayStat.connectionCompleted / item.relayStat.connectionTentatives.toFloat()) * 100).toInt()
+
Icon(
imageVector = Icons.Default.SyncProblem,
stringRes(R.string.errors),
modifier = Size15Modifier,
tint =
- if (item.relayStat.errorCounter > 0) {
+ if (successRate < 0.1) {
+ MaterialTheme.colorScheme.redColorOnSecondSurface
+ } else if (successRate < 0.60) {
MaterialTheme.colorScheme.warningColor
} else {
MaterialTheme.colorScheme.allGoodColor
@@ -145,7 +151,7 @@ fun RelayStatusRow(
)
Text(
- text = countToHumanReadable(item.relayStat.errorCounter, "errors"),
+ text = stringResource(R.string.uptime, successRate),
maxLines = 1,
fontSize = Font12SP,
modifier = HalfStartPadding,
diff --git a/amethyst/src/main/res/values/strings.xml b/amethyst/src/main/res/values/strings.xml
index e3c481298..cb6c1d222 100644
--- a/amethyst/src/main/res/values/strings.xml
+++ b/amethyst/src/main/res/values/strings.xml
@@ -137,6 +137,7 @@
Bytes
Error
Errors
+ Percentage of successful connections to the relay
The number of connection errors in this session
Home Feed
Private Message Feed
@@ -1743,4 +1744,5 @@
Following %1$d accounts…
"Enter the profile of a friend or community leader. You can use their npub, NIP-05 address, or a Namecoin name like alice@example.bit or id/alice for blockchain-verified identities."
Select All
+ %1$d% uptime
diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStat.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStat.kt
index 58d3acf8d..64349dcaf 100644
--- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStat.kt
+++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStat.kt
@@ -32,6 +32,8 @@ class RelayStat(
var errorCounter: Int = 0,
var pingInMs: Int = 0,
var compression: Boolean = false,
+ var connectionTentatives: Int = 0,
+ var connectionCompleted: Int = 0,
) {
val messages = LruCache(100)
@@ -63,6 +65,14 @@ class RelayStat(
sentBytes += bytesUsedInMemory
}
+ fun newConnection() {
+ connectionTentatives++
+ }
+
+ fun connectionCompleted() {
+ connectionCompleted++
+ }
+
fun newSpam(
link1: String,
link2: String,
diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStats.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStats.kt
index 44c8fb084..fdd0c60ef 100644
--- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStats.kt
+++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip01Core/relay/client/stats/RelayStats.kt
@@ -46,6 +46,13 @@ class RelayStats(
private val clientListener =
object : IRelayClientListener {
+ override fun onConnecting(relay: IRelayClient) {
+ super.onConnecting(relay)
+ with(get(relay.url)) {
+ newConnection()
+ }
+ }
+
override fun onConnected(
relay: IRelayClient,
pingMillis: Int,
@@ -54,6 +61,7 @@ class RelayStats(
with(get(relay.url)) {
pingInMs = pingMillis
compression = compressed
+ connectionCompleted()
}
}