From cac7be6c22bafc0d43fe209813c1fc1ac31a0190 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Mon, 3 Feb 2025 18:13:15 +0200 Subject: Fixed a bug where users weren't able to scroll higher if they already got to the top message but then more messages have been added --- internal/client/ui/core/state/state.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'internal/client/ui/core/state') diff --git a/internal/client/ui/core/state/state.go b/internal/client/ui/core/state/state.go index 08b8c55..1115c13 100644 --- a/internal/client/ui/core/state/state.go +++ b/internal/client/ui/core/state/state.go @@ -13,14 +13,14 @@ import ( "github.com/kyren223/eko/pkg/snowflake" ) -type FrequencyState struct { +type ChatState struct { IncompleteMessage string Base int MaxHeight int } type state struct { - ChatState map[snowflake.ID]FrequencyState // key is frequency id or receiver id + ChatState map[snowflake.ID]ChatState // key is frequency id or receiver id LastFrequency map[snowflake.ID]snowflake.ID // key is network id Messages map[snowflake.ID]*btree.BTreeG[data.Message] // key is frequency id or receiver id @@ -34,7 +34,7 @@ type state struct { } var State state = state{ - ChatState: map[snowflake.ID]FrequencyState{}, + ChatState: map[snowflake.ID]ChatState{}, LastFrequency: map[snowflake.ID]snowflake.ID{}, Messages: map[snowflake.ID]*btree.BTreeG[data.Message]{}, Networks: map[snowflake.ID]data.Network{}, @@ -168,6 +168,18 @@ func UpdateMessages(info *packet.MessagesInfo) { } bt.ReplaceOrInsert(message) } + + // Note: this is a naive approach + // Ideally we check each message that was added/removed + // For the frequency/receiver/sender id and only remove that + // But it can be very slow when there are thousands of messages + // TODO: when msg chunking is implemented, consider doing it per-msg + // TODO: consider checking messages count and for small counts use + // the per message approach + for id, state := range State.ChatState { + state.MaxHeight = -1 + State.ChatState[id] = state + } } func UpdateMembers(info *packet.MembersInfo) { -- cgit v1.3.1