dkforest

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

commit 4ef5f2c497c4e2947d01c5bd7b733fae8da9f8f3
parent b02dfcadbdb4afcf42151bcbc1cdfb8599ab4358
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 12 Jan 2023 15:13:44 -0800

cleanup

Diffstat:
Mpkg/utils/utils.go | 10++++++++++
Mpkg/web/handlers/api/v1/handlers.go | 13++++---------
2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go @@ -956,3 +956,13 @@ func InArr[T comparable](needle T, haystack []T) bool { } return false } + +// CountBools given booleans, returns how many are set to true +func CountBools(vals ...bool) (count int64) { + for _, v := range vals { + if v { + count++ + } + } + return count +} diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -161,15 +161,10 @@ func ChatMessagesHandler(c echo.Context) error { data.OfficialRooms, _ = database.GetOfficialChatRooms1(authUser.ID) data.SubscribedRooms, _ = database.GetUserRoomSubscriptions(authUser.ID) - if authUser.DisplayHellbanButton { - data.NbButtons += 1 - } - if authUser.DisplayKickButton { - data.NbButtons += 1 - } - if authUser.DisplayDeleteButton { - data.NbButtons += 1 - } + data.NbButtons = utils.CountBools( + authUser.DisplayHellbanButton, + authUser.DisplayKickButton, + authUser.DisplayDeleteButton) if c.QueryParams().Has("json") { return c.JSON(http.StatusOK, data)