commit a53eb90c19a998f4946782d5a822aa3c96e3a9bd
parent 7b4f7deda30192b9b4d34827f7041690e6370a39
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 2 Mar 2023 17:42:49 -0800
configurable HB opacity
Diffstat:
7 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/cmd/dkf/migrations/128.sql b/cmd/dkf/migrations/128.sql
@@ -0,0 +1,4 @@
+-- +migrate Up
+ALTER TABLE users ADD COLUMN hellban_opacity INTEGER DEFAULT 30;
+
+-- +migrate Down
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -50,6 +50,7 @@ type User struct {
DisplayDeleteButton bool
PmMode int64 // Normal: 0, Whitelist 1
DisplayPms int64 // deprecated
+ HellbanOpacity int64
DisplayIgnored bool
HideIgnoredUsersFromList bool
Verified bool
@@ -244,6 +245,10 @@ func (u *User) CanSeeHB() bool {
return u.CanSeeHellbanned || u.IsModerator()
}
+func (u *User) GetHellbanOpacityF64() float64 {
+ return float64(u.HellbanOpacity) / 100
+}
+
// Save user in the database
func (u *User) Save() error {
return DB.Save(u).Error
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -631,6 +631,7 @@ type settingsChatData struct {
DisplayHellbanned bool
DisplayModerators bool
HideIgnoredUsersFromList bool
+ HellbanOpacity float64
HideRightColumn bool
ChatBarAtBottom bool
AutocompleteCommandsEnabled bool
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -2480,6 +2480,7 @@ func SettingsChatHandler(c echo.Context) error {
data.SpellcheckEnabled = authUser.SpellcheckEnabled
data.AfkIndicatorEnabled = authUser.AfkIndicatorEnabled
data.HideIgnoredUsersFromList = authUser.HideIgnoredUsersFromList
+ data.HellbanOpacity = float64(authUser.HellbanOpacity) / 100
data.RefreshRate = authUser.RefreshRate
data.NotifyNewMessage = authUser.NotifyNewMessage
data.NotifyTagged = authUser.NotifyTagged
@@ -3094,6 +3095,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
data.Theme = utils.Clamp(utils.DoParseInt64(c.Request().PostFormValue("theme")), 0, 2)
data.NotifyChessGames = utils.DoParseBool(c.Request().PostFormValue("notify_chess_games"))
data.NotifyChessMove = utils.DoParseBool(c.Request().PostFormValue("notify_chess_move"))
+ data.HellbanOpacity = utils.DoParseF64(c.Request().PostFormValue("hellban_opacity"))
//data.NotifyNewMessageSound = utils.DoParseInt64(c.Request().PostFormValue("notify_new_message_sound"))
//data.NotifyTaggedSound = utils.DoParseInt64(c.Request().PostFormValue("notify_tagged_sound"))
//data.NotifyPmmedSound = utils.DoParseInt64(c.Request().PostFormValue("notify_pmmed_sound"))
@@ -3134,6 +3136,9 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
//authUser.NotifyTaggedSound = data.NotifyTaggedSound
//authUser.NotifyPmmedSound = data.NotifyPmmedSound
+ if authUser.CanSeeHB() {
+ authUser.HellbanOpacity = utils.Clamp(int64(data.HellbanOpacity*100), 0, 100)
+ }
if authUser.IsModerator() {
authUser.DisplayHellbanned = data.DisplayHellbanned
authUser.DisplayModerators = data.DisplayModerators
diff --git a/pkg/web/public/views/pages/chat-archive.gohtml b/pkg/web/public/views/pages/chat-archive.gohtml
@@ -75,7 +75,7 @@
<div class="mb-3">
{{ range .Data.Messages }}
{{ if (.UserCanSee $.AuthUser) }}
- <div class="msg" style="border-bottom: 1px solid #444; color: #888; position: relative;{{ if and (or .User.IsHellbanned .IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7); opacity: 0.3;{{ end }}" id="{{ .UUID }}">
+ <div class="msg" style="border-bottom: 1px solid #444; color: #888; position: relative;{{ if and (or .User.IsHellbanned .IsHellbanned) $.AuthUser.DisplayHellbanned }} background-color: rgba(0, 0, 0, 0.7); opacity: {{ $.AuthUser.GetHellbanOpacityF64 }};{{ end }}" id="{{ .UUID }}">
{{ if (.UserCanDelete $.AuthUser) }}
{{ if not .TooOldToDelete }}
<form method="post" action="/api/v1/chat/messages/delete/{{ .UUID }}" style="display: inline;">
diff --git a/pkg/web/public/views/pages/chat-messages.gohtml b/pkg/web/public/views/pages/chat-messages.gohtml
@@ -153,7 +153,7 @@
.f-orange-clr { color: orange; }
.f-white-clr, .f-white-clr:hover { color: white; }
.line-through { text-decoration: line-through; }
- .hb-row { background-color: rgba(0, 0, 0, 0.7); opacity: 0.3; }
+ .hb-row { background-color: rgba(0, 0, 0, 0.7); opacity: {{ $.AuthUser.GetHellbanOpacityF64 }}; }
.own-highlight { background-color: rgba(255,241,176,0.05); }
.read-marker { border-top: {{ $.AuthUser.ChatReadMarkerSize }}px solid {{ $.AuthUser.ChatReadMarkerColor }}; }
#msgs { {{ if not .AuthUser.HideRightColumn }}width: calc(100% - 170px); float: left; {{ end }}line-height: 1.2; }
diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml
@@ -105,6 +105,13 @@
<hr />
+ {{ if $.AuthUser.CanSeeHB }}
+ <div>
+ <label for="hellban_opacity" class="toggle"><span>Hellban opacity</span></label>
+ <input name="hellban_opacity" id="hellban_opacity" type="number" min="0.1" max="1.0" step="0.1" value="{{ .Data.HellbanOpacity }}" />
+ </div>
+ {{ end }}
+
<div class="form-group">
<div class="form-check form-check-1">
<div class="checkbox-wrapper form-check-input">