commit bc83ec6ad4b2ac0eb57c6e772b77c742aa9c5815
parent bc96b2b89113fdb25fd0dbbb39cf866f68a00340
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 22 May 2023 23:30:25 -0700
Add setting to use "stream" version by default
Diffstat:
6 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/cmd/dkf/migrations/132.sql b/cmd/dkf/migrations/132.sql
@@ -0,0 +1,4 @@
+-- +migrate Up
+ALTER TABLE users ADD COLUMN use_stream TINYINT(1) NOT NULL DEFAULT 0;
+
+-- +migrate Down
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -104,6 +104,7 @@ type User struct {
Theme int64
GeneralMessagesCount int64
AFK bool
+ UseStream bool
HighlightOwnMessages bool `gorm:"-"`
}
diff --git a/pkg/web/handlers/chat.go b/pkg/web/handlers/chat.go
@@ -15,6 +15,11 @@ func chatHandler(c echo.Context, redRoom, stream bool) error {
const chatPasswordTmplName = "standalone.chat-password"
authUser := c.Get("authUser").(*database.User)
db := c.Get("database").(*database.DkfDB)
+
+ if !stream {
+ stream = authUser.UseStream
+ }
+
var data chatData
data.RedRoom = redRoom
preventRefresh := utils.DoParseBool(c.QueryParam("r"))
diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go
@@ -652,6 +652,7 @@ type settingsChatData struct {
DisplayDeleteButton bool
DisplayKickButton bool
DisplayHellbanButton bool
+ UseStream bool
NotifyChessGames bool
NotifyChessMove bool
NotifyNewMessage bool
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -2479,6 +2479,7 @@ func SettingsChatHandler(c echo.Context) error {
data.Theme = authUser.Theme
data.NotifyChessGames = authUser.NotifyChessGames
data.NotifyChessMove = authUser.NotifyChessMove
+ data.UseStream = authUser.UseStream
if c.Request().Method == http.MethodGet {
return c.Render(http.StatusOK, "settings.chat", data)
@@ -3100,6 +3101,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.UseStream = utils.DoParseBool(c.Request().PostFormValue("use_stream"))
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"))
@@ -3136,6 +3138,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error {
authUser.NotifyPmmed = data.NotifyPmmed
authUser.NotifyChessGames = data.NotifyChessGames
authUser.NotifyChessMove = data.NotifyChessMove
+ authUser.UseStream = data.UseStream
authUser.Theme = data.Theme
//authUser.NotifyNewMessageSound = data.NotifyNewMessageSound
//authUser.NotifyTaggedSound = data.NotifyTaggedSound
diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml
@@ -176,6 +176,13 @@
</div>
<label class="form-check-label" for="notify_chess_move">{{ t "Notify chess move" . }}</label>
</div>
+ <div class="form-check form-check-1">
+ <div class="checkbox-wrapper form-check-input">
+ <input class="my-cbx" type="checkbox" name="use_stream" id="use_stream" value="1"{{ if .Data.UseStream }} checked{{ end }} />
+ <label for="use_stream" class="toggle"><span></span></label>
+ </div>
+ <label class="form-check-label" for="use_stream">{{ t "Use chat stream version" . }}</label>
+ </div>
{{ if $.AuthUser.IsModerator }}
<div class="form-check form-check-1">
<div class="checkbox-wrapper form-check-input">