From 57569b6b5678f137df4db0ea979a63a966968bd5 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Wed, 2 Dec 2026 11:40:04 +0100 Subject: [PATCH] fix(android): stop the history walk on an empty page loadOlder returned as soon as a page held no events, before clearing moreOlder. The screen kept thinking older turns existed and asked again each time the list settled. Against the mock claw, opening a session with no cached transcript sent six /history requests where one was enough. An empty page clears moreOlder now, even when the response's more flag says otherwise. With no event to move oldestSeq, another request would only repeat the same empty answer. assembleDebug passes; the same session sends one history request. --- .../rs/rhema/phone/chat/ChatController.kt | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt b/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt index 7e6aa3b..29898f1 100644 --- a/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt +++ b/android/app/src/main/java/rs/rhema/phone/chat/ChatController.kt @@ -256,13 +256,20 @@ class ChatController( val page = result.value.events.mapNotNull { entry -> entry.event?.let { entry.seq to it } } - val first = page.firstOrNull() ?: return - // The page is older than everything on screen, and the - // list runs oldest first: it goes above, never below — - // appended, it would land at the newest end. - items = applyEvents(emptyList(), page.map { it.second }) + items - oldestSeq = first.first - moreOlder = result.value.more + val first = page.firstOrNull() + if (first == null) { + // An empty page cannot move the anchor back, so + // retrying would only repeat this request. Stop + // even when `more` promised rows it did not send. + moreOlder = false + } else { + // The page is older than everything on screen, and + // the list runs oldest first: it goes above, never + // below — appended, it would land at the newest end. + items = applyEvents(emptyList(), page.map { it.second }) + items + oldestSeq = first.first + moreOlder = result.value.more + } } is ClawResult.HttpError, is ClawResult.Network -> Unit }