commit f6b977badccfca1cb75ec50e3b6a1ebe32052bf1
parent 07c25a6b3e99347a124c8ca9165a5ca56030e09c
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 1 Jan 2024 17:55:44 -0500
cleanup
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/pkg/database/tableUsers.go b/pkg/database/tableUsers.go
@@ -363,6 +363,14 @@ func (u *User) DoSave(db *DkfDB) {
}
}
+func (u *User) ToggleAutocompleteCommandsEnabled(db *DkfDB) {
+ db.db.Model(u).Select("AutocompleteCommandsEnabled").Updates(User{AutocompleteCommandsEnabled: !u.AutocompleteCommandsEnabled})
+}
+
+func (u *User) SetCaptchaRequired(db *DkfDB, captchaRequired bool) {
+ db.db.Model(u).Select("CaptchaRequired").Updates(User{CaptchaRequired: captchaRequired})
+}
+
func (u *User) SetSyntaxHighlightCode(db *DkfDB, syntaxHighlightCode string) {
db.db.Model(u).Select("SyntaxHighlightCode").Updates(User{SyntaxHighlightCode: syntaxHighlightCode})
}
diff --git a/pkg/web/handlers/interceptors/slashInterceptor.go b/pkg/web/handlers/interceptors/slashInterceptor.go
@@ -382,8 +382,7 @@ func handleForceCaptchaCmd(c *command.Command) (handled bool) {
}
if c.AuthUser.IsAdmin || !user.IsModerator() || c.AuthUser.Username == username {
c.DB.NewAudit(*c.AuthUser, fmt.Sprintf("force captcha %s #%d", user.Username, user.ID))
- user.CaptchaRequired = true
- user.DoSave(c.DB)
+ user.SetCaptchaRequired(c.DB, true)
database.MsgPubSub.Pub("refresh_"+string(user.Username), database.ChatMessageType{Typ: database.ForceRefresh})
}
c.Err = command.ErrRedirect
@@ -1593,8 +1592,7 @@ func handleUnIgnoreCmd(c *command.Command) (handled bool) {
func handleToggleAutocomplete(c *command.Command) (handled bool) {
if c.Message == "/toggle-autocomplete" {
- c.AuthUser.AutocompleteCommandsEnabled = !c.AuthUser.AutocompleteCommandsEnabled
- c.AuthUser.DoSave(c.DB)
+ c.AuthUser.ToggleAutocompleteCommandsEnabled(c.DB)
c.Err = command.ErrRedirect
return true
}