From bfcec338c8a40cb553693e1f12d9f290598e6205 Mon Sep 17 00:00:00 2001 From: sanasol Date: Wed, 4 Mar 2026 23:05:40 +0100 Subject: [PATCH] fix: prevent channel wipe on WS reconnect race condition When the WS connects (including first connection), pushReconnectEvent() triggers loadMessages(50, ignoreExisting=true). If the initial load already fetched the same messages, ignoreExisting filters them all out, producing an empty list that updateItems() uses to clear the channel. Skip the update entirely when ignoreExisting yields no new messages. Signed-off-by: sanasol --- .../screens/chat/views/channel/ChannelScreenViewModel.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/chat/stoat/screens/chat/views/channel/ChannelScreenViewModel.kt b/app/src/main/java/chat/stoat/screens/chat/views/channel/ChannelScreenViewModel.kt index ac571556..98467e00 100644 --- a/app/src/main/java/chat/stoat/screens/chat/views/channel/ChannelScreenViewModel.kt +++ b/app/src/main/java/chat/stoat/screens/chat/views/channel/ChannelScreenViewModel.kt @@ -535,6 +535,13 @@ class ChannelScreenViewModel @Inject constructor( } } + // Skip update if ignoreExisting filtered out all messages (e.g. WS reconnect + // fetched the same messages already loaded) — otherwise updateItems([]) wipes the list + if (ignoreExisting && newItems.isEmpty()) { + if (!didInitialChannelFetch) didInitialChannelFetch = true + return@launch + } + // Place items according to whether above/below/around was specified. // TODO: Aditionally, place LoadTriggers at the beginning and end of the list. val newItemsWithPosition = when {