commit 7250d0c0e2eedccee4ae956db76460830958496c
parent cedd8d70295929d3ea68950316b4c0e5a709a79a
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 4 Jun 2023 00:19:49 -0700
user can change background color
Diffstat:
6 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/cmd/dkf/migrations/134.sql b/cmd/dkf/migrations/134.sql
@@ -0,0 +1,4 @@
+-- +migrate Up
+ALTER TABLE users ADD COLUMN chat_background_color VARCHAR(20) DEFAULT '#222222' NOT NULL;
+
+-- +migrate Down
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -70,6 +70,7 @@ type User struct {
ApiKey string
Lang string
ChatColor string
+ ChatBackgroundColor string
ChatFont int64
ChatBold bool
ChatItalic bool
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -645,6 +645,7 @@ type shopData struct {
type settingsChatData struct {
ActiveTab string
ChatColor string
+ ChatBackgroundColor string
ChatFont int64
RefreshRate int64
ChatBold bool
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -2472,6 +2472,7 @@ func SettingsChatHandler(c echo.Context) error {
data.ActiveTab = "chat"
data.AllFonts = utils.GetFonts()
data.ChatColor = authUser.ChatColor
+ data.ChatBackgroundColor = authUser.ChatBackgroundColor
data.ChatFont = authUser.ChatFont
data.ChatItalic = authUser.ChatItalic
data.ChatBold = authUser.ChatBold
@@ -3099,6 +3100,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
data.RefreshRate = utils.Clamp(utils.DoParseInt64(c.Request().PostFormValue("refresh_rate")), 5, 60)
data.ChatColor = c.Request().PostFormValue("chat_color")
+ data.ChatBackgroundColor = c.Request().PostFormValue("chat_background_color")
data.ChatFont = utils.DoParseInt64(c.Request().PostFormValue("chat_font"))
data.ChatBold = utils.DoParseBool(c.Request().PostFormValue("chat_bold"))
data.DateFormat = utils.Clamp(utils.DoParseInt64(c.Request().PostFormValue("date_format")), 0, 4)
@@ -3130,7 +3132,11 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
//data.NotifyPmmedSound = utils.DoParseInt64(c.Request().PostFormValue("notify_pmmed_sound"))
colorRgx := regexp.MustCompile(`^#[0-9a-fA-F]{6}$`)
if !colorRgx.MatchString(data.ChatColor) {
- data.Error = "Invalid color format"
+ data.Error = "Invalid color format (text)"
+ return c.Render(http.StatusOK, "settings.chat", data)
+ }
+ if !colorRgx.MatchString(data.ChatBackgroundColor) {
+ data.Error = "Invalid color format (background)"
return c.Render(http.StatusOK, "settings.chat", data)
}
if !colorRgx.MatchString(data.ChatReadMarkerColor) {
@@ -3141,6 +3147,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
if authUser.CanChangeColor {
authUser.ChatColor = data.ChatColor
}
+ authUser.ChatBackgroundColor = data.ChatBackgroundColor
authUser.ChatFont = data.ChatFont
authUser.ChatItalic = data.ChatItalic
authUser.ChatBold = data.ChatBold
diff --git a/pkg/web/public/views/pages/chat.gohtml b/pkg/web/public/views/pages/chat.gohtml
@@ -6,6 +6,10 @@
body {
background-color: #3b0000 !important;
}
+ {{ else }}
+ body {
+ background-color: {{ .AuthUser.ChatBackgroundColor }} !important;
+ }
{{ end }}
#chat-top-bar {
border: 0;
diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml
@@ -42,15 +42,22 @@
<label for="refresh_rate">{{ t "Refresh rate" . }}</label>
<input type="number" min="5" max="60" id="refresh_rate" name="refresh_rate" value="{{ .Data.RefreshRate }}" class="form-control" />
</div>
- {{ if .AuthUser.CanChangeColor }}
- <div class="form-group">
- <label for="chat_color">{{ t "Chat color" . }}</label>
+ <div>
+ <div class="form-group d-inline-block mr-3">
+ <label for="chat_color">{{ t "Text color" . }}</label>
<div class="input-group color-pkr">
<div class="input-group-prepend"><span style="background-color: {{ .Data.ChatColor }};" class="input-group-text"></span></div>
- <input type="color" id="chat_color" name="chat_color" value="{{ .Data.ChatColor }}" class="form-control" />
+ <input type="color" id="chat_color" name="chat_color" value="{{ .Data.ChatColor }}" class="form-control"{{ if not .AuthUser.CanChangeColor }} disabled{{ end }} />
</div>
</div>
- {{ end }}
+ <div class="form-group d-inline-block mr-3">
+ <label for="chat_background_color">{{ t "Background color" . }}</label>
+ <div class="input-group color-pkr">
+ <div class="input-group-prepend"><span style="background-color: {{ .Data.ChatBackgroundColor }};" class="input-group-text"></span></div>
+ <input type="color" id="chat_background_color" name="chat_background_color" value="{{ .Data.ChatBackgroundColor }}" class="form-control" />
+ </div>
+ </div>
+ </div>
<div class="form-group">
<label for="chat_font">{{ t "Font" . }}</label>
<select name="chat_font" id="chat_font" class="form-control">