From f75ad32728f67307f0fd0e2e36648a092e0b824f Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sat, 16 Dec 2023 15:10:48 -0800 Subject: [PATCH] Ban command update, join/leave messages * The /ban command doesn't require the target user to be online at the time of the ban. * Update the presence messages so they will generally only go to the primary (first) public channel, and also to another public channel if the user is currently looking at one of the others. --- pkg/commands.go | 14 ++++++-------- pkg/handlers.go | 1 - src/App.vue | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pkg/commands.go b/pkg/commands.go index c702eeb..06e4298 100644 --- a/pkg/commands.go +++ b/pkg/commands.go @@ -229,14 +229,11 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) { log.Info("Operator %s bans %s for %d hours", sub.Username, username, duration/time.Hour) - other, err := s.GetSubscriber(username) - if err != nil { - sub.ChatServer("/ban: username not found: %s", username) - } else { - // Ban them. - BanUser(username, duration) + // Add them to the ban list. + BanUser(username, duration) - // Broadcast it to everyone. + // If the target user is currently online, disconnect them and broadcast the ban to everybody. + if other, err := s.GetSubscriber(username); err == nil { s.Broadcast(messages.Message{ Action: messages.ActionPresence, Username: username, @@ -249,8 +246,9 @@ func (s *Server) BanCommand(words []string, sub *Subscriber) { }) other.authenticated = false other.Username = "" - sub.ChatServer("%s has been banned from the room for %d hours.", username, duration/time.Hour) } + + sub.ChatServer("%s has been banned from the room for %d hours.", username, duration/time.Hour) } // UnbanCommand handles the `/unban` operator command. diff --git a/pkg/handlers.go b/pkg/handlers.go index e076f42..599115b 100644 --- a/pkg/handlers.go +++ b/pkg/handlers.go @@ -83,7 +83,6 @@ func (s *Server) OnLogin(sub *Subscriber, msg messages.Message) { sub.SendJSON(messages.Message{ Action: messages.ActionKick, }) - s.DeleteSubscriber(sub) return } diff --git a/src/App.vue b/src/App.vue index 2ca5f2a..71b9028 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1277,12 +1277,22 @@ export default { isJoin = true; } - // Push it to the history of all public channels (depending on user preference). + // Push it to the history of the public channels (respecting user preferences). if ((isJoin && this.prefs.joinMessages) || (isLeave && this.prefs.exitMessages) || (!isJoin && !isLeave)) { - for (let channel of this.config.channels) { + // Always put them in the first public channel. + let channel = this.config.channels[0]; + this.pushHistory({ + channel: channel.ID, + action: msg.action, + username: msg.username, + message: msg.message, + }); + + // If the current user is focused on another public channel, also post it there. + if (!this.isDM && this.channel !== channel.ID) { this.pushHistory({ - channel: channel.ID, + channel: this.channel.ID, action: msg.action, username: msg.username, message: msg.message,