dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit d42ee05814e3fc2a2bfd95dd80fd1670162c3c05
parent 802cb907df87032d4f3ee7c7c13f641e2aa54cdd
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 30 May 2023 09:59:39 -0700

fix read-marker at top when a message is deleted

Diffstat:
Mpkg/web/handlers/handlers.go | 21+++++++++++++++++++++
1 file changed, 21 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5108,6 +5108,16 @@ func ChatStreamMessagesHandler(c echo.Context) error { readMarkerRev := 0 + // Keep track of messages that are after the read-marker (unread). + // When we receive a "delete msg", and this map is empty, we should hide the read-marker + // as it means the read marker is now at the very top. + msgsMap := make(map[int64]struct{}) + for _, msg := range msgs { + if msg.CreatedAt.After(data.ReadMarker.ReadAt) { + msgsMap[msg.ID] = struct{}{} + } + } + // If the read-marker is at the very top, it will be hidden and need to be displayed when we receive a new message. // If it is not at the top, it will already be visible and does not need to be displayed again. var displayReadMarker bool @@ -5157,6 +5167,7 @@ Loop: } if topic == readMarkerTopic { + msgsMap = make(map[int64]struct{}) // read-marker at the top, so no unread message send(fmt.Sprintf(`<style>.read-marker-%d{display:none !important;}</style>`, readMarkerRev)) send(fmt.Sprintf(`<div class="read-marker read-marker-%d" style="display:none;"></div>`, readMarkerRev+1)) readMarkerRev++ @@ -5171,6 +5182,14 @@ Loop: } if msgTyp.Typ == database.DeleteMsg { + delete(msgsMap, msgTyp.Msg.ID) + if len(msgsMap) == 0 { + send(fmt.Sprintf(`<style>.read-marker-%d{display:none !important;}</style>`, readMarkerRev)) + send(fmt.Sprintf(`<div class="read-marker read-marker-%d" style="display:none;"></div>`, readMarkerRev+1)) + readMarkerRev++ + displayReadMarker = true + } + send(fmt.Sprintf(`<style>.msgidc-%s-%d{display:none;}</style>`, msgTyp.Msg.UUID, msgTyp.Msg.Rev)) c.Response().Flush() continue @@ -5226,6 +5245,8 @@ Loop: isFirstMsg := false renderedMsg := v1.RenderMessage(1, *msg, authUser, data, baseTopBarURL, &readMarkerRendered, &isFirstMsg, csrf, nullUsername) + msgsMap[msg.ID] = struct{}{} + send(renderedMsg) if displayReadMarker { send(fmt.Sprintf(`<style>.read-marker-%d{display:block !important;}</style>`, readMarkerRev))