dkforest

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

commit 0b2894e403de9bb2b48a22d414876b29591bb38a
parent 7281a4c2fddd33596c0c3fd45df54c65e554a7f2
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 30 May 2023 18:15:16 -0700

cleanup

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

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5106,8 +5106,6 @@ func ChatStreamMessagesHandler(c echo.Context) error { sub := database.MsgPubSub.Subscribe(authorizedTopics) defer sub.Close() - 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. @@ -5127,6 +5125,14 @@ func ChatStreamMessagesHandler(c echo.Context) error { displayReadMarker = fstMsgTsRound.Before(readMarkerTsRound) || fstMsgTsRound.Equal(readMarkerTsRound) } + readMarkerRev := 0 + updateReadMarker := func() { + 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 + } + // Toggle between true/false every 5sec. This bool keep track of which class to send for our "online indicator" // We need to change the css class in order for the css to never actually complete the animation and stay "green". var indicatorSelector bool @@ -5170,10 +5176,7 @@ Loop: // This means the user is saying that all messages are read, and read-marker should be at the very top. 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++ - displayReadMarker = true + updateReadMarker() c.Response().Flush() continue } @@ -5188,10 +5191,7 @@ Loop: // If the map is now empty, we hide the read-marker. 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 + updateReadMarker() } send(fmt.Sprintf(`<style>.msgidc-%s-%d{display:none;}</style>`, msgTyp.Msg.UUID, msgTyp.Msg.Rev))