From 62b4798881d3c98b83b6458e0665c5dae7d84504 Mon Sep 17 00:00:00 2001 From: Paul Hitt Date: Wed, 26 Aug 2026 12:00:15 -0400 Subject: [PATCH] "Nobody here yet" was also what a failed load looked like MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔴 **A claim about the account, made about a request that failed.** Both roster load sites swallow failures with `runCatching { … }.getOrDefault(emptyList())`, so a network hiccup, an expired token or a rate limit all produced an empty list — and the contacts card then said "Nobody here yet. Add someone by the username they signed up with." Someone whose contacts had simply failed to fetch was told they had none. Found by auditing the shape that hid the iOS group bug: a swallowed failure that renders as a confident empty state. Six such sites exist on Android; the two on the sign-in and restore paths are the ones a user meets first. `Phase.SignedIn` now carries `buddiesLoaded`, defaulting to FALSE so a phase built without saying so cannot assert the fetch succeeded. The empty state only claims emptiness when the list actually loaded; otherwise it says the load failed and what to do. Verified on the emulator with the radios off: the card reads "Couldn't load your contacts. Check the connection and sign in again." With the network back, the roster loads and the contact shows as before. ⚠️ Four sites remain that still default to empty on failure — groups, stories, and two others. They deserve the same treatment; contacts came first because it is the screen somebody lands on. Android suites green (194 tests). Co-Authored-By: Claude Opus 5 --- .../io/flamenet/messenger/app/ChatScreens.kt | 11 ++++- .../messenger/app/MessengerViewModel.kt | 22 ++++++++- .../messenger/app/EmptyVersusFailedTest.kt | 45 +++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/src/test/kotlin/io/flamenet/messenger/app/EmptyVersusFailedTest.kt diff --git a/app/src/main/kotlin/io/flamenet/messenger/app/ChatScreens.kt b/app/src/main/kotlin/io/flamenet/messenger/app/ChatScreens.kt index d63178f..a8d8e8a 100644 --- a/app/src/main/kotlin/io/flamenet/messenger/app/ChatScreens.kt +++ b/app/src/main/kotlin/io/flamenet/messenger/app/ChatScreens.kt @@ -141,10 +141,19 @@ fun ColumnScope.BuddyList(model: MessengerViewModel, phase: MessengerViewModel.P } if (phase.buddies.isEmpty()) { + // ⚠️ Only claim the list is empty if it was actually FETCHED. A failed + // load also produces an empty list, and "Nobody here yet" is then a + // statement about the person's account rather than about the request — + // which is how somebody concludes their contacts are gone. + // // Says what to do, not merely that there is nothing. An empty state // that only reports emptiness leaves the person stuck. Text( - "Nobody here yet. Add someone by the username they signed up with.", + if (phase.buddiesLoaded) { + "Nobody here yet. Add someone by the username they signed up with." + } else { + "Couldn't load your contacts. Check the connection and sign in again." + }, style = MaterialTheme.typography.bodyMedium, ) return diff --git a/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt b/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt index 51471a9..5c636d1 100644 --- a/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt +++ b/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt @@ -51,6 +51,20 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) { val relay: String, val status: String, val buddies: List = emptyList(), + + /** + * Whether the contact list was actually FETCHED, as opposed to + * defaulted to empty because the fetch failed. + * + * 🔴 Both load sites swallow failures with + * `runCatching { … }.getOrDefault(emptyList())`, so a network + * hiccup, an expired token or a rate limit all produced an empty + * roster — and the UI then told the user "Nobody here yet", which + * is a claim about their account rather than about the request. + * The same swallow-and-look-empty shape hid a decode bug that made + * groups invisible on iOS for far longer. + */ + val buddiesLoaded: Boolean = false, val groups: List = emptyList(), val blocked: Set = emptySet(), val notifications: List = emptyList(), @@ -221,13 +235,15 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) { api = MessengerApi( credential.relayBaseUrl, credential.username, credential.appPassword), ) + val fetchedBuddies = runCatching { session!!.api.buddies() } stored to Phase.SignedIn( handle = credential.username, userId = credential.userId, deviceId = stored.deviceId, relay = SiteConfig(credential.relayBaseUrl).host, status = "Signed in on this device.", - buddies = runCatching { session!!.api.buddies() }.getOrDefault(emptyList()), + buddies = fetchedBuddies.getOrDefault(emptyList()), + buddiesLoaded = fetchedBuddies.isSuccess, groups = runCatching { session!!.relay.listGroups() }.getOrDefault(emptyList()), ) } @@ -334,13 +350,15 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) { api = io.flamenet.client.MessengerApi(config.baseUrl, account.username, credential), ) + val fetchedBuddies = runCatching { session!!.api.buddies() } return Phase.SignedIn( handle = account.username, userId = account.userId, deviceId = device.deviceId, relay = config.host, status = "Registered with ${preKeys.size} one-time prekeys published.", - buddies = runCatching { session!!.api.buddies() }.getOrDefault(emptyList()), + buddies = fetchedBuddies.getOrDefault(emptyList()), + buddiesLoaded = fetchedBuddies.isSuccess, groups = runCatching { session!!.relay.listGroups() }.getOrDefault(emptyList()), ) } diff --git a/app/src/test/kotlin/io/flamenet/messenger/app/EmptyVersusFailedTest.kt b/app/src/test/kotlin/io/flamenet/messenger/app/EmptyVersusFailedTest.kt new file mode 100644 index 0000000..8abab0c --- /dev/null +++ b/app/src/test/kotlin/io/flamenet/messenger/app/EmptyVersusFailedTest.kt @@ -0,0 +1,45 @@ +package io.flamenet.messenger.app + +import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * "Nobody here yet" is a claim about the ACCOUNT. It must not be made about a + * request that failed. + * + * 🔴 Both roster load sites swallow failures with + * `runCatching { … }.getOrDefault(emptyList())`, so a hiccup, an expired token + * or a rate limit all produced an empty list — indistinguishable from a real + * empty account. The same swallow-and-look-empty shape hid a decode bug that + * made groups invisible on iOS. + */ +class EmptyVersusFailedTest { + + private fun phase(loaded: Boolean) = MessengerViewModel.Phase.SignedIn( + handle = "someone", + userId = 1, + deviceId = "d", + relay = "relay.example", + status = "", + buddies = emptyList(), + buddiesLoaded = loaded, + ) + + @Test + fun `an empty roster that loaded is not the same state as one that failed`() { + assertNotEquals(phase(loaded = true), phase(loaded = false)) + } + + @Test + fun `a failed load does not default to claiming the roster loaded`() { + // The default matters: a phase built without saying so must not assert + // that the fetch succeeded. + val untouched = MessengerViewModel.Phase.SignedIn( + handle = "someone", userId = 1, deviceId = "d", + relay = "relay.example", status = "", + ) + assertTrue("the default must be 'not loaded', so the copy stays honest", + !untouched.buddiesLoaded) + } +}