dkforest

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

commit ce99188459f2e51cfb738f57be1a30be98c28302
parent 94aad9add635acff5a9ea43c6821bcd46a349e32
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 28 Jun 2023 11:05:15 -0700

add support for manual multiline

Diffstat:
Acmd/dkf/migrations/145.sql | 4++++
Mpkg/database/tableUsers.go | 1+
Mpkg/database/utils/processMessage.go | 8+++++---
Mpkg/web/handlers/data.go | 1+
Mpkg/web/handlers/interceptors/bangInterceptor.go | 2+-
Mpkg/web/handlers/interceptors/command/command.go | 2+-
Mpkg/web/handlers/interceptors/msgInterceptor.go | 2+-
Mpkg/web/handlers/interceptors/slashInterceptor.go | 2+-
Mpkg/web/handlers/interceptors/werewolf.go | 2+-
Mpkg/web/handlers/settings.go | 5+++++
Mpkg/web/public/views/pages/settings/chat.gohtml | 9+++++++++
11 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/cmd/dkf/migrations/145.sql b/cmd/dkf/migrations/145.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE users ADD COLUMN manual_multiline TINYINT(1) NOT NULL DEFAULT 0; + +-- +migrate Down diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go @@ -99,6 +99,7 @@ type User struct { CanUseUppercase bool CanChangeColor bool CanUseMultiline bool + ManualMultiline bool CanUseChessAnalyze bool Vetted bool RegistrationDuration int64 diff --git a/pkg/database/utils/processMessage.go b/pkg/database/utils/processMessage.go @@ -99,9 +99,9 @@ var msgPolicy = bluemonday.NewPolicy(). // ProcessRawMessage return the new html, and a map of tagged users used for notifications // This function takes an "unsafe" user input "in", and return html which will be safe to render. func ProcessRawMessage(db *database.DkfDB, in, roomKey string, authUserID database.UserID, roomID database.RoomID, - upload *database.Upload, canUseMultiline bool) (string, map[database.UserID]database.User, error) { + upload *database.Upload, canUseMultiline, manualML bool) (string, map[database.UserID]database.User, error) { html, quoted := convertQuote(db, in, roomKey, roomID) // Get raw quote text which is not safe to render - html = convertNewLines(html, canUseMultiline) + html = convertNewLines(html, canUseMultiline, manualML) html = html2.EscapeString(html) // Makes user input safe to render // All html generated from this point on shall be safe to render. html = convertPGPClearsignToFile(db, html, authUserID) @@ -235,9 +235,11 @@ func GetQuoteTxt(db *database.DkfDB, roomKey string, quoted database.ChatMessage return `“[` + quoted.CreatedAt.Format("15:04:05") + "]" + remaining + `”` } -func convertNewLines(html string, canUseMultiline bool) string { +func convertNewLines(html string, canUseMultiline, manualML bool) string { if !canUseMultiline { html = strings.ReplaceAll(html, "\n", "") + } else if manualML { + html = strings.ReplaceAll(html, "\\n", "\n") } return html } diff --git a/pkg/web/handlers/data.go b/pkg/web/handlers/data.go @@ -672,6 +672,7 @@ type settingsChatData struct { DisplayKickButton bool DisplayHellbanButton bool UseStream bool + ManualMultiline bool ConfirmExternalLinks bool ChessSoundsEnabled bool NotifyChessGames bool diff --git a/pkg/web/handlers/interceptors/bangInterceptor.go b/pkg/web/handlers/interceptors/bangInterceptor.go @@ -24,7 +24,7 @@ Chats: Black Hat Chat: ` + config.BhcOnion + ` Forums: CryptBB: ` + config.CryptbbOnion - msg, _, _ := dutils.ProcessRawMessage(cmd.DB, message, "", cmd.AuthUser.ID, cmd.Room.ID, nil, true) + msg, _, _ := dutils.ProcessRawMessage(cmd.DB, message, "", cmd.AuthUser.ID, cmd.Room.ID, nil, true, false) cmd.ZeroMsg(msg) cmd.Err = command.ErrRedirect } diff --git a/pkg/web/handlers/interceptors/command/command.go b/pkg/web/handlers/interceptors/command/command.go @@ -108,7 +108,7 @@ func (c *Command) zeroProcMsgRoom(rawMsg, roomKey string, roomID database.RoomID // Have the "zero user" send a "processed message" PM to a user in a specific room. func (c *Command) zeroProcMsgRoomToUser(rawMsg, roomKey string, roomID database.RoomID, toUser *database.User) { - procMsg, _, _ := dutils.ProcessRawMessage(c.DB, rawMsg, roomKey, c.AuthUser.ID, roomID, nil, true) + procMsg, _, _ := dutils.ProcessRawMessage(c.DB, rawMsg, roomKey, c.AuthUser.ID, roomID, nil, true, false) c.zeroRawMsg(toUser, rawMsg, procMsg) } diff --git a/pkg/web/handlers/interceptors/msgInterceptor.go b/pkg/web/handlers/interceptors/msgInterceptor.go @@ -98,7 +98,7 @@ func (i MsgInterceptor) InterceptMsg(cmd *command.Command) { return } - html, taggedUsersIDsMap, err := dutils.ProcessRawMessage(cmd.DB, cmd.Message, cmd.RoomKey, cmd.AuthUser.ID, cmd.Room.ID, cmd.Upload, cmd.AuthUser.CanUseMultiline) + html, taggedUsersIDsMap, err := dutils.ProcessRawMessage(cmd.DB, cmd.Message, cmd.RoomKey, cmd.AuthUser.ID, cmd.Room.ID, cmd.Upload, cmd.AuthUser.CanUseMultiline, cmd.AuthUser.ManualMultiline) if err != nil { cmd.DataMessage = cmd.OrigMessage cmd.Err = err diff --git a/pkg/web/handlers/interceptors/slashInterceptor.go b/pkg/web/handlers/interceptors/slashInterceptor.go @@ -1255,7 +1255,7 @@ func handleInboxCmd(c *command.Command) (handled bool) { html = strings.Join(strings.Split(html, "\n"), " ") } - html, _, _ = dutils.ProcessRawMessage(c.DB, html, c.RoomKey, c.AuthUser.ID, c.Room.ID, nil, c.AuthUser.CanUseMultiline) + html, _, _ = dutils.ProcessRawMessage(c.DB, html, c.RoomKey, c.AuthUser.ID, c.Room.ID, nil, c.AuthUser.CanUseMultiline, c.AuthUser.ManualMultiline) c.DB.CreateInboxMessage(html, c.Room.ID, c.AuthUser.ID, toUser.ID, true, false, nil) c.DataMessage = "/inbox " + string(username) + " " diff --git a/pkg/web/handlers/interceptors/werewolf.go b/pkg/web/handlers/interceptors/werewolf.go @@ -331,7 +331,7 @@ func (b *Werewolf) isValidPlayerName(name string) bool { // Narrate register a chat message on behalf of the narrator user func (b *Werewolf) Narrate(msg string, toUserID *database.UserID, groupID *database.GroupID) { - html, _, _ := dutils.ProcessRawMessage(b.db, msg, "", b.narratorID, b.roomID, nil, true) + html, _, _ := dutils.ProcessRawMessage(b.db, msg, "", b.narratorID, b.roomID, nil, true, false) b.NarrateRaw(html, toUserID, groupID) } diff --git a/pkg/web/handlers/settings.go b/pkg/web/handlers/settings.go @@ -67,6 +67,7 @@ func SettingsChatHandler(c echo.Context) error { data.UseStream = authUser.UseStream data.ConfirmExternalLinks = authUser.ConfirmExternalLinks data.ChessSoundsEnabled = authUser.ChessSoundsEnabled + data.ManualMultiline = authUser.ManualMultiline if c.Request().Method == http.MethodGet { return c.Render(http.StatusOK, "settings.chat", data) @@ -116,6 +117,7 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error { 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.ManualMultiline = utils.DoParseBool(c.Request().PostFormValue("manual_multiline")) //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")) @@ -174,6 +176,9 @@ func changeSettingsForm(c echo.Context, data settingsChatData) error { authUser.DisplayKickButton = data.DisplayKickButton authUser.DisplayHellbanButton = data.DisplayHellbanButton } + if authUser.CanUseMultiline { + authUser.ManualMultiline = data.ManualMultiline + } if err := authUser.Save(db); err != nil { logrus.Error(err) diff --git a/pkg/web/public/views/pages/settings/chat.gohtml b/pkg/web/public/views/pages/settings/chat.gohtml @@ -173,6 +173,15 @@ </div> <label class="form-check-label" for="display_delete_button">{{ t "Display delete button" . }}</label> </div> + {{ if $.AuthUser.CanUseMultiline }} + <div class="form-check form-check-1"> + <div class="checkbox-wrapper form-check-input"> + <input class="my-cbx" type="checkbox" name="manual_multiline" id="manual_multiline" value="1"{{ if .Data.ManualMultiline }} checked{{ end }} /> + <label for="manual_multiline" class="toggle"><span></span></label> + </div> + <label class="form-check-label" for="manual_multiline">{{ t "Enable manual multiline" . }}</label> + </div> + {{ end }} <div class="form-check form-check-1"> <div class="checkbox-wrapper form-check-input"> <input class="my-cbx" type="checkbox" name="notify_chess_games" id="notify_chess_games" value="1"{{ if .Data.NotifyChessGames }} checked{{ end }} />