dkforest

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

commit bbbf62a7a655559def85e25cb4dd54c0d4a5a177
parent 5c1279a9fd7ffe60a2383909dcd851ac24d9daae
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue,  6 Jun 2023 00:39:58 -0700

simplify code

Diffstat:
Mpkg/web/handlers/api/v1/msgInterceptor.go | 2+-
Mpkg/web/handlers/api/v1/topBarHandler.go | 4+---
Mpkg/web/handlers/api/v1/werewolf.go | 14+++++++-------
3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/pkg/web/handlers/api/v1/msgInterceptor.go b/pkg/web/handlers/api/v1/msgInterceptor.go @@ -46,7 +46,7 @@ func (i MsgInterceptor) InterceptMsg(cmd *Command) { toUserID := database.UserPtrID(cmd.toUser) - msgID, _ := cmd.db.CreateOrEditMessage(cmd.editMsg, html, cmd.origMessage, cmd.roomKey, cmd.room.ID, cmd.fromUserID, toUserID, cmd.upload, cmd.groupID, cmd.hellbanMsg, cmd.modMsg, cmd.systemMsg) + msgID, _ := cmd.db.CreateOrEditMessage(cmd.editMsg, html, cmd.origMessage, cmd.roomKey, cmd.room.ID, cmd.authUser.ID, toUserID, cmd.upload, cmd.groupID, cmd.hellbanMsg, cmd.modMsg, cmd.systemMsg) if !cmd.skipInboxes { sendInboxes(cmd.db, cmd.room, cmd.authUser, cmd.toUser, msgID, cmd.groupID, html, cmd.modMsg, taggedUsersIDsMap) diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go @@ -387,9 +387,8 @@ type Command struct { message string // Un-sanitized message received from the user room database.ChatRoom // Room the user is in roomKey string // Room password (if any) - authUser *database.User // Authenticated user + authUser *database.User // Authenticated user (sender of the message) db *database.DkfDB // Database instance - fromUserID database.UserID // Sender of message toUser *database.User // If not nil, will be a PM upload *database.Upload // If the message contains an uploaded file editMsg *database.ChatMessage // If we're editing a message @@ -409,7 +408,6 @@ func NewCommand(c echo.Context, origMessage string, room database.ChatRoom, room c: c, authUser: authUser, db: db, - fromUserID: authUser.ID, hellbanMsg: authUser.IsHellbanned, redirectQP: url.Values{}, origMessage: origMessage, diff --git a/pkg/web/handlers/api/v1/werewolf.go b/pkg/web/handlers/api/v1/werewolf.go @@ -122,7 +122,7 @@ func (b *Werewolf) InterceptNightMsg(cmd *Command) { cmd.err = errors.New("narrator doesn't need your input") } return - } else if b.isForNarrator(cmd) && b.seerID != nil && cmd.fromUserID == *b.seerID { + } else if b.isForNarrator(cmd) && b.seerID != nil && cmd.authUser.ID == *b.seerID { select { case b.seerCh <- cmd.message: cmd.err = ErrRedirect @@ -130,7 +130,7 @@ func (b *Werewolf) InterceptNightMsg(cmd *Command) { cmd.err = errors.New("narrator doesn't need your input") } return - } else if b.isForNarrator(cmd) && b.healerID != nil && cmd.fromUserID == *b.healerID { + } else if b.isForNarrator(cmd) && b.healerID != nil && cmd.authUser.ID == *b.healerID { select { case b.healerCh <- cmd.message: cmd.err = ErrRedirect @@ -149,20 +149,20 @@ func (b *Werewolf) isForNarrator(cmd *Command) bool { } func (b *Werewolf) InterceptVoteMsg(cmd *Command) { - if !b.isAlivePlayer(cmd.fromUserID) || !b.isForNarrator(cmd) { + if !b.isAlivePlayer(cmd.authUser.ID) || !b.isForNarrator(cmd) { cmd.err = errors.New("chat disabled") return } if b.isForNarrator(cmd) { - if !b.voted.Contains(cmd.fromUserID) { + if !b.voted.Contains(cmd.authUser.ID) { name := cmd.message if b.isValidPlayerName(name) { b.votesCh <- name } else { - b.Narrate(ErrInvalidPlayerName.Error(), &cmd.fromUserID, nil) + b.Narrate(ErrInvalidPlayerName.Error(), &cmd.authUser.ID, nil) } } else { - b.Narrate("You have already voted", &cmd.fromUserID, nil) + b.Narrate("You have already voted", &cmd.authUser.ID, nil) } } } @@ -188,7 +188,7 @@ func (b *Werewolf) InterceptMsg(cmd *Command) { SlashInterceptor{}.InterceptMsg(cmd) // If the message is a PM not for the narrator, we reject it - if cmd.toUser != nil && (cmd.toUser.ID != b.narratorID && cmd.fromUserID != b.narratorID) { + if cmd.toUser != nil && (cmd.toUser.ID != b.narratorID && cmd.authUser.ID != b.narratorID) { cmd.err = errors.New("PM not allowed at this room") return }