dkforest

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

commit c53f76f15c100c300e9d8d78f6df1e4f0896dafa
parent 6d02ef69cd1d9c99a4f4118c921d09191f855ffc
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 12 Jun 2023 11:17:52 -0700

Add chess sounds

Diffstat:
Acmd/dkf/migrations/141.sql | 4++++
Mpkg/database/tableUsers.go | 1+
Mpkg/web/handlers/data.go | 1+
Mpkg/web/handlers/handlers.go | 11+++++++++++
Apkg/web/public/sounds/chess/Capture.ogg | 0
Apkg/web/public/sounds/chess/GenericNotify.ogg | 0
Apkg/web/public/sounds/chess/Move.ogg | 0
Mpkg/web/public/views/pages/settings/chat.gohtml | 7+++++++
8 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/cmd/dkf/migrations/141.sql b/cmd/dkf/migrations/141.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE users ADD COLUMN chess_sounds_enabled TINYINT(1) NOT NULL DEFAULT 0; + +-- +migrate Down diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -119,6 +119,7 @@ type User struct { UseStream bool SyntaxHighlightCode string ConfirmExternalLinks bool + ChessSoundsEnabled bool HighlightOwnMessages bool `gorm:"-"` } diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -673,6 +673,7 @@ type settingsChatData struct { DisplayHellbanButton bool UseStream bool ConfirmExternalLinks bool + ChessSoundsEnabled bool NotifyChessGames bool NotifyChessMove bool NotifyNewMessage bool diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -2574,6 +2574,7 @@ func SettingsChatHandler(c echo.Context) error { data.NotifyChessMove = authUser.NotifyChessMove data.UseStream = authUser.UseStream data.ConfirmExternalLinks = authUser.ConfirmExternalLinks + data.ChessSoundsEnabled = authUser.ChessSoundsEnabled if c.Request().Method == http.MethodGet { return c.Render(http.StatusOK, "settings.chat", data) @@ -3221,6 +3222,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error { data.NotifyChessMove = utils.DoParseBool(c.Request().PostFormValue("notify_chess_move")) data.UseStream = utils.DoParseBool(c.Request().PostFormValue("use_stream")) data.ConfirmExternalLinks = utils.DoParseBool(c.Request().PostFormValue("confirm_external_links")) + data.ChessSoundsEnabled = utils.DoParseBool(c.Request().PostFormValue("chess_sounds_enabled")) data.HellbanOpacity = utils.DoParseF64(c.Request().PostFormValue("hellban_opacity")) data.CodeBlockHeight = utils.DoParseInt64(c.Request().PostFormValue("code_block_height")) //data.NotifyNewMessageSound = utils.DoParseInt64(c.Request().PostFormValue("notify_new_message_sound")) @@ -3265,6 +3267,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error { authUser.NotifyChessMove = data.NotifyChessMove authUser.UseStream = data.UseStream authUser.ConfirmExternalLinks = data.ConfirmExternalLinks + authUser.ChessSoundsEnabled = data.ChessSoundsEnabled authUser.Theme = data.Theme //authUser.NotifyNewMessageSound = data.NotifyNewMessageSound //authUser.NotifyTaggedSound = data.NotifyTaggedSound @@ -5192,6 +5195,14 @@ Loop: send(fmt.Sprintf(`<style>#%s { display: none; }</style>`, payload.EnPassant)) } + if authUser.ChessSoundsEnabled { + if payload.Move.HasTag(chess.Capture) || payload.Move.HasTag(chess.EnPassant) { + send(`<audio src="/public/sounds/chess/Capture.ogg" autoplay></audio>`) + } else { + send(`<audio src="/public/sounds/chess/Move.ogg" autoplay></audio>`) + } + } + // Render advantages whiteAdv, whiteScore, blackAdv, blackScore := interceptors.CalcAdvantage(g.Game.Position()) send(fmt.Sprintf(`<style>#white-advantage:before { content: "%s" !important; }</style>`, whiteAdv)) diff --git a/pkg/web/public/sounds/chess/Capture.ogg b/pkg/web/public/sounds/chess/Capture.ogg Binary files differ. diff --git a/pkg/web/public/sounds/chess/GenericNotify.ogg b/pkg/web/public/sounds/chess/GenericNotify.ogg Binary files differ. diff --git a/pkg/web/public/sounds/chess/Move.ogg b/pkg/web/public/sounds/chess/Move.ogg Binary files differ. diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml @@ -201,6 +201,13 @@ </div> <label class="form-check-label" for="confirm_external_links">Confirm before opening external links</label> </div> + <div class="form-check form-check-1"> + <div class="checkbox-wrapper form-check-input"> + <input class="my-cbx" type="checkbox" name="chess_sounds_enabled" id="chess_sounds_enabled" value="1"{{ if .AuthUser.ChessSoundsEnabled }} checked{{ end }} /> + <label for="chess_sounds_enabled" class="toggle"><span></span></label> + </div> + <label class="form-check-label" for="chess_sounds_enabled">Enabled chess sounds</label> + </div> {{ if $.AuthUser.IsModerator }} <div class="form-check form-check-1"> <div class="checkbox-wrapper form-check-input">