dkforest

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

commit c712657e9369c1d63beb0824b4bfe8cf06ce1ffa
parent 1c4552d7a97942eda6b2ef6c83865d9b6c9b6622
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon,  6 Feb 2023 00:36:23 -0800

toggle HB is no good when multiple mods click the button at the same time.

Diffstat:
Mpkg/web/handlers/api/v1/handlers.go | 15++++++++++++++-
Mpkg/web/public/views/pages/chat-archive.gohtml | 15+++++++++++----
Mpkg/web/public/views/pages/chat-messages.gohtml | 15+++++++++++----
Mpkg/web/web.go | 3++-
4 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -281,7 +281,20 @@ func UserHellbanHandler(c echo.Context) error { user.HellBan() managers.ActiveUsers.UpdateUserHBInRooms(managers.NewUserInfo(user, nil)) } - } else { + } + } + return c.Redirect(http.StatusFound, c.Request().Referer()) +} + +func UserUnHellbanHandler(c echo.Context) error { + authUser := c.Get("authUser").(*database.User) + if authUser.IsModerator() { + userID := dutils.DoParseUserID(c.Param("userID")) + user, err := database.GetUserByID(userID) + if err != nil { + return c.Redirect(http.StatusFound, c.Request().Referer()) + } + if user.IsHellbanned { database.NewAudit(*authUser, fmt.Sprintf("unhellban %s #%d", user.Username, user.ID)) user.UnHellBan() managers.ActiveUsers.UpdateUserHBInRooms(managers.NewUserInfo(user, nil)) diff --git a/pkg/web/public/views/pages/chat-archive.gohtml b/pkg/web/public/views/pages/chat-archive.gohtml @@ -94,10 +94,17 @@ {{ end }} {{ if $.AuthUser.IsModerator }} {{ if ne .UserID $.AuthUser.ID }} - <form method="post" action="/api/v1/users/{{ .UserID }}/toggle-hellban" style="display: inline;"> - <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> - <button class="mod-btn hb_btn" style="color: orange; {{ if .User.IsHellbanned }}text-decoration: line-through;{{ end }}" title="hellban"></button> - </form> + {{- if .User.IsHellbanned -}} + <form method="post" action="/api/v1/users/{{ .UserID }}/unhellban" style="display: inline;"> + <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> + <button class="mod-btn hb_btn" style="color: orange; text-decoration: line-through;" title="unhellban"></button> + </form> + {{- else -}} + <form method="post" action="/api/v1/users/{{ .UserID }}/hellban" style="display: inline;"> + <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> + <button class="mod-btn hb_btn" style="color: orange;" title="hellban"></button> + </form> + {{- end -}} <form method="post" action="/api/v1/users/{{ .UserID }}/kick" style="display: inline;"> <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> <button class="mod-btn k_btn" style="color: orange;" title="kick"></button> diff --git a/pkg/web/public/views/pages/chat-messages.gohtml b/pkg/web/public/views/pages/chat-messages.gohtml @@ -246,10 +246,17 @@ {{- if eq .User.Username $.NullUsername -}} <div class="spacer16"></div> {{- else -}} - <form method="post" action="/api/v1/users/{{ .UserID }}/toggle-hellban" class="d-inline"> - <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> - <button class="mod-btn hb_btn f-orange-clr{{ if .User.IsHellbanned }} line-through{{ end }}" title="hellban"></button> - </form> + {{- if .User.IsHellbanned -}} + <form method="post" action="/api/v1/users/{{ .UserID }}/unhellban" class="d-inline"> + <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> + <button class="mod-btn hb_btn f-orange-clr line-through" title="unhellban"></button> + </form> + {{- else -}} + <form method="post" action="/api/v1/users/{{ .UserID }}/hellban" class="d-inline"> + <input type="hidden" name="csrf" value="{{ $.CSRF }}" /> + <button class="mod-btn hb_btn f-orange-clr" title="hellban"></button> + </form> + {{- end -}} {{- end -}} {{- end -}} {{- if $.AuthUser.DisplayKickButton -}} diff --git a/pkg/web/web.go b/pkg/web/web.go @@ -147,7 +147,8 @@ func getMainServer(i18nBundle *i18n.Bundle, renderer *tmp.Templates) echo.Handle authGroup.POST("/api/v1/inbox/delete-all", v1.ChatInboxDeleteAllMessageHandler) authGroup.POST("/api/v1/chat/messages/delete/:messageUUID", v1.ChatDeleteMessageHandler) authGroup.POST("/api/v1/chat/messages/reactions", v1.ChatMessageReactionHandler) - authGroup.POST("/api/v1/users/:userID/toggle-hellban", v1.UserHellbanHandler) + authGroup.POST("/api/v1/users/:userID/hellban", v1.UserHellbanHandler) + authGroup.POST("/api/v1/users/:userID/unhellban", v1.UserUnHellbanHandler) authGroup.POST("/api/v1/users/:userID/kick", v1.KickHandler) authGroup.POST("/api/v1/rooms/:roomName/subscribe", v1.SubscribeHandler) authGroup.POST("/api/v1/rooms/:roomName/unsubscribe", v1.UnsubscribeHandler)