dkforest

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

commit 068a06541e9872973893f434483d9ae42f9cb560
parent 133b39e403409c885eb8817f876757f10506ba56
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 11 Jan 2023 11:41:14 -0800

cleanup

Diffstat:
Mpkg/web/handlers/chat.go | 77+++++++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 47 insertions(+), 30 deletions(-)

diff --git a/pkg/web/handlers/chat.go b/pkg/web/handlers/chat.go @@ -76,44 +76,20 @@ func chatHandler(c echo.Context, redRoom bool) error { formName := c.Request().PostFormValue("formName") switch formName { case "toggle-hb": - if authUser.CanSeeHB() { - authUser.DisplayHellbanned = !authUser.DisplayHellbanned - authUser.DoSave() - } - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleToggleHBPost(c, authUser) case "toggle-m": - if authUser.IsModerator() { - authUser.DisplayModerators = !authUser.DisplayModerators - authUser.DoSave() - } - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleToggleMPost(c, authUser) case "toggle-ignored": - authUser.DisplayIgnored = !authUser.DisplayIgnored - authUser.DoSave() - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleToggleIgnoredPost(c, authUser) case "afk": - authUser.AFK = !authUser.AFK - authUser.DoSave() - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleAfkPost(c, authUser) case "update-read-marker": - database.UpdateChatReadMarker(authUser.ID, room.ID) - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleUpdateReadMarkerPost(c, room, authUser) case "tutorialP1", "tutorialP2", "tutorialP3": - if authUser.ChatTutorial < 3 && time.Since(authUser.ChatTutorialTime) >= time.Duration(data.TutoSecs)*time.Second { - authUser.ChatTutorial++ - authUser.DoSave() - } - return c.Redirect(http.StatusFound, c.Request().Referer()) - + return handleTutorialPost(c, data, authUser) case "chat-password": return handleChatPasswordPost(c, data, authUser, room) } - return c.Redirect(http.StatusFound, c.Request().Referer()) } @@ -127,6 +103,47 @@ func chatHandler(c echo.Context, redRoom bool) error { return c.Render(http.StatusOK, "chat", data) } +func handleToggleHBPost(c echo.Context, authUser *database.User) error { + if authUser.CanSeeHB() { + authUser.DisplayHellbanned = !authUser.DisplayHellbanned + authUser.DoSave() + } + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func handleToggleMPost(c echo.Context, authUser *database.User) error { + if authUser.IsModerator() { + authUser.DisplayModerators = !authUser.DisplayModerators + authUser.DoSave() + } + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func handleToggleIgnoredPost(c echo.Context, authUser *database.User) error { + authUser.DisplayIgnored = !authUser.DisplayIgnored + authUser.DoSave() + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func handleAfkPost(c echo.Context, authUser *database.User) error { + authUser.AFK = !authUser.AFK + authUser.DoSave() + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func handleUpdateReadMarkerPost(c echo.Context, room database.ChatRoom, authUser *database.User) error { + database.UpdateChatReadMarker(authUser.ID, room.ID) + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func handleTutorialPost(c echo.Context, data chatData, authUser *database.User) error { + if authUser.ChatTutorial < 3 && time.Since(authUser.ChatTutorialTime) >= time.Duration(data.TutoSecs)*time.Second { + authUser.ChatTutorial++ + authUser.DoSave() + } + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + // Handle POST requests for chat-password, when someone tries to authenticate in a protected room providing a password. func handleChatPasswordPost(c echo.Context, data chatData, authUser *database.User, room database.ChatRoom) error { data.RoomPassword = c.Request().PostFormValue("password")