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/chat/chat.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'internal/client/ui/core/chat/chat.go') diff --git a/internal/client/ui/core/chat/chat.go b/internal/client/ui/core/chat/chat.go index 528c02b..9451de7 100644 --- a/internal/client/ui/core/chat/chat.go +++ b/internal/client/ui/core/chat/chat.go @@ -210,6 +210,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { frequency := frequencies[m.frequencyIndex] member := state.State.Members[*networkId][*state.UserID] + if s, ok := state.State.ChatState[frequency.ID]; ok { + m.maxMessagesHeight = s.MaxHeight + } + lastMsg := state.GetLastMessage(frequency.ID) if m.base != SnapToBottom { m.keepLastRead = false @@ -257,6 +261,10 @@ func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { } else if m.receiverIndex != -1 { receiverId := state.Data.Peers[m.receiverIndex] + if s, ok := state.State.ChatState[receiverId]; ok { + m.maxMessagesHeight = s.MaxHeight + } + lastMsg := state.GetLastMessage(receiverId) if m.base == SnapToBottom && lastMsg != nil { lastReadMsg := state.Data.LastReadMessage[receiverId] @@ -713,7 +721,7 @@ func (m *Model) ResetBeforeSwitch() { } frequencyId := frequencies[m.frequencyIndex].ID log.Println("Saving frequency", frequencyId) - state.State.ChatState[frequencyId] = state.FrequencyState{ + state.State.ChatState[frequencyId] = state.ChatState{ IncompleteMessage: m.vi.String(), Base: m.base, MaxHeight: m.maxMessagesHeight, @@ -724,7 +732,7 @@ func (m *Model) ResetBeforeSwitch() { } else if m.receiverIndex != -1 { receiverId := state.Data.Peers[m.receiverIndex] log.Println("Saving signal:", receiverId) - state.State.ChatState[receiverId] = state.FrequencyState{ + state.State.ChatState[receiverId] = state.ChatState{ IncompleteMessage: m.vi.String(), Base: m.base, MaxHeight: m.maxMessagesHeight, @@ -951,6 +959,14 @@ func (m *Model) renderMessages(screenHeight int) string { if ok && last == first.ID { m.maxMessagesHeight = height - remainingHeight m.SetIndex(m.index) + if s, ok := state.State.ChatState[*id]; ok { + s.MaxHeight = m.maxMessagesHeight + state.State.ChatState[*id] = s + } else { + state.State.ChatState[*id] = state.ChatState{ + MaxHeight: m.maxMessagesHeight, + } + } } var builder strings.Builder -- cgit v1.3.1