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 <mail@sanasol.ws>
This commit is contained in:
sanasol 2026-03-04 23:05:40 +01:00
parent dda158a848
commit bfcec338c8
1 changed files with 7 additions and 0 deletions

View File

@ -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 {