dkforest

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

commit 9aed54a153913707a99eb793ef1adb1f4d173fe5
parent 768832a72497e7d63e83eaa213781d6d73f5ada5
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 12 Jan 2023 19:30:25 -0800

simplify code

Diffstat:
Mpkg/web/handlers/api/v1/handlers.go | 9+++++----
Mpkg/web/public/views/pages/chat-messages.gohtml | 18++++++------------
2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -161,10 +161,11 @@ func ChatMessagesHandler(c echo.Context) error { data.OfficialRooms, _ = database.GetOfficialChatRooms1(authUser.ID) data.SubscribedRooms, _ = database.GetUserRoomSubscriptions(authUser.ID) - data.NbButtons = utils.CountBools( - authUser.DisplayHellbanButton, - authUser.DisplayKickButton, - authUser.DisplayDeleteButton) + bools := []bool{authUser.DisplayDeleteButton} + if authUser.IsModerator() { + bools = append(bools, authUser.DisplayHellbanButton, authUser.DisplayKickButton) + } + data.NbButtons = utils.CountBools(bools...) if c.QueryParams().Has("json") { return c.JSON(http.StatusOK, data) diff --git a/pkg/web/public/views/pages/chat-messages.gohtml b/pkg/web/public/views/pages/chat-messages.gohtml @@ -248,18 +248,12 @@ {{- end -}} {{- end -}} {{- else -}} - {{- if $.AuthUser.IsModerator -}} - {{- if eq $.Data.NbButtons 3 -}} - <div class="spacer56"></div>&nbsp; - {{- else if eq $.Data.NbButtons 2 -}} - <div class="spacer36"></div>&nbsp; - {{- else if eq $.Data.NbButtons 1 -}} - <div class="spacer16"></div>&nbsp; - {{- end -}} - {{- else -}} - {{- if $.AuthUser.DisplayDeleteButton -}} - <div class="spacer16"></div>&nbsp; - {{- end -}} + {{- if eq $.Data.NbButtons 3 -}} + <div class="spacer56"></div>&nbsp; + {{- else if eq $.Data.NbButtons 2 -}} + <div class="spacer36"></div>&nbsp; + {{- else if eq $.Data.NbButtons 1 -}} + <div class="spacer16"></div>&nbsp; {{- end -}} {{- end -}} {{- if ne $.Data.DateFormat "" -}}