dkforest

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

commit 4102d7d4abb64435b0a315a830e327ce99c219f6
parent a27d7440fc2d033b526ce7ef62131ae032810f4a
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 30 May 2023 03:20:32 -0700

fix crash if no mesasges

Diffstat:
Mpkg/web/handlers/handlers.go | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5110,9 +5110,12 @@ func ChatStreamMessagesHandler(c echo.Context) error { // 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. - fstMsgTsRound := msgs[0].CreatedAt.Round(time.Second) - readMarkerTsRound := data.ReadMarker.ReadAt.Round(time.Second) - displayReadMarker := fstMsgTsRound.Before(readMarkerTsRound) || fstMsgTsRound.Equal(readMarkerTsRound) + var displayReadMarker bool + if len(msgs) > 0 { + fstMsgTsRound := msgs[0].CreatedAt.Round(time.Second) + readMarkerTsRound := data.ReadMarker.ReadAt.Round(time.Second) + displayReadMarker = fstMsgTsRound.Before(readMarkerTsRound) || fstMsgTsRound.Equal(readMarkerTsRound) + } // 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".