Consumes the SDK surface from PR #58 (`Wire.outbox(pubkeyHex)` → `OutboxRow { messageId, status, attempts, nextAttemptAt, lastError }` and `outboxMaxAttempts()`): a queued chat row now says *why* it is still queued instead of a flat `queued`. * `OutboxDetail.kt` — `retryInText` mirrors `src/tui.rs::retry_in_text` (`<= 0` → `retry now`; `< 60` → `retry {n}s`; else `retry {ceil-minutes}m`), and `outboxDetails` joins the SDK's rows onto the chat rows. The denominator is the core's `outboxMaxAttempts()`/`Rust` budget, fetched once — never 8. * A terminal `"failed"` row keeps the marker's own `failed: <reason>` and gets **no** countdown: `nextAttemptAt` on a failed row is the last time it was scheduled for, so a countdown there would promise an attempt that never comes. `"sending"` stays bare, matching the TUI. * `ChatScreen` polls the outbox rows on the same 2s cadence as the bodies and renders the countdown against an injectable `nowSeconds` (the store holds an absolute instant, the app computes the age). * The join is positional — `ChatMessage` carries no `messages.id` — and fail-closed: mismatched row counts, an unknown status, or a status that contradicts the one the SDK resolved for that message drops every detail and leaves the flat markers. `ChatMessage.id` would remove the positional part; filed as follow-up. * `OutboxDetailTest` (17 tests) asserts the three `retry_in_text` buckets, the `queued (try 3/8, retry 45s)` wording, that a failed row shows no countdown, that the denominator comes from the caller, and the three fail-closed cases. 32 unit tests, 0 failures. Android base: PR #56 (`feat/android-outbox-state`, t_f46a9863) — the Android half of the #52/#56 duplicate pair, which is not merged here. SDK base: PR #58 on PR #51.
122 lines
4.3 KiB
Kotlin
122 lines
4.3 KiB
Kotlin
package com.siriusdevops.onionwire
|
|
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
import androidx.navigation.NavType
|
|
import androidx.navigation.compose.NavHost
|
|
import androidx.navigation.compose.composable
|
|
import androidx.navigation.compose.rememberNavController
|
|
import androidx.navigation.navArgument
|
|
import com.siriusdevops.onionwire.ui.ChatScreen
|
|
import com.siriusdevops.onionwire.ui.PasteInviteScreen
|
|
import com.siriusdevops.onionwire.ui.RosterScreen
|
|
import com.siriusdevops.onionwire.ui.RotateScreen
|
|
import com.siriusdevops.onionwire.ui.ShareInviteScreen
|
|
import com.siriusdevops.onionwire.ui.UnlockScreen
|
|
import com.siriusdevops.onionwire.ui.OnionWireTheme
|
|
import kotlinx.coroutines.launch
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
enableEdgeToEdge()
|
|
setContent {
|
|
OnionWireTheme {
|
|
Surface(
|
|
modifier = Modifier.fillMaxSize(),
|
|
color = MaterialTheme.colorScheme.background,
|
|
) {
|
|
AppRoot()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun AppRoot(vm: WireViewModel = viewModel()) {
|
|
val phase by vm.phase.collectAsStateWithLifecycle()
|
|
|
|
when (val p = phase) {
|
|
is Phase.Ready -> ReadyGraph(vm, p)
|
|
else -> UnlockScreen(phase = p, onUnlock = vm::unlock)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
private fun ReadyGraph(vm: WireViewModel, ready: Phase.Ready) {
|
|
val nav = rememberNavController()
|
|
val friends by vm.friends.collectAsStateWithLifecycle()
|
|
val scope = rememberCoroutineScope()
|
|
|
|
NavHost(navController = nav, startDestination = "roster") {
|
|
composable("roster") {
|
|
RosterScreen(
|
|
fingerprint = ready.fingerprint,
|
|
onion = ready.onion,
|
|
sdkVersion = ready.sdkVersion,
|
|
friends = friends,
|
|
onOpenChat = { nav.navigate("chat/${it.pubkeyHex}") },
|
|
onShare = { nav.navigate("share") },
|
|
onPaste = { nav.navigate("paste") },
|
|
onRotate = { nav.navigate("rotate") },
|
|
onWipe = { scope.launch { vm.wipeMessages() } },
|
|
onLock = vm::lock,
|
|
)
|
|
}
|
|
|
|
composable("share") {
|
|
ShareInviteScreen(ownerInvite = vm::invite, onBack = { nav.popBackStack() })
|
|
}
|
|
|
|
composable("paste") {
|
|
PasteInviteScreen(
|
|
onDecode = vm::decode,
|
|
onAdd = vm::addFriend,
|
|
onBack = { nav.popBackStack() },
|
|
)
|
|
}
|
|
|
|
composable("rotate") {
|
|
RotateScreen(
|
|
currentOnion = ready.onion,
|
|
onRotate = {
|
|
val out = vm.rotateOnion()
|
|
out.notified.toInt() to out.friends.toInt()
|
|
},
|
|
onBack = { nav.popBackStack() },
|
|
)
|
|
}
|
|
|
|
composable(
|
|
route = "chat/{pk}",
|
|
arguments = listOf(navArgument("pk") { type = NavType.StringType }),
|
|
) { entry ->
|
|
val pk = entry.arguments?.getString("pk").orEmpty()
|
|
val friend = friends.firstOrNull { it.pubkeyHex == pk }
|
|
ChatScreen(
|
|
title = friend?.petname?.takeIf { it.isNotBlank() }
|
|
?: friend?.fingerprint
|
|
?: pk.take(16),
|
|
fingerprint = friend?.fingerprint ?: pk.take(16),
|
|
onion = friend?.onion.orEmpty(),
|
|
loadMessages = { vm.messages(pk) },
|
|
loadOutbox = { vm.outbox(pk) },
|
|
loadMaxAttempts = { vm.outboxMaxAttempts() },
|
|
onSend = { body -> vm.send(pk, body) },
|
|
onBack = { nav.popBackStack() },
|
|
)
|
|
}
|
|
}
|
|
}
|