Quit and part messages can sometimes be useful for knowing if, e.g. a user spamming channels got K-Lined, or if a netsplit is occuring, among other things. As said in #senpai: f_ delthas: Anyway, for example, just now someone spammed a channel on another network (Rizon) but then quit f_ I cannot know if that user has already been k-lined or if they just left the channel. delthas f_: OK, so maybe a global toggle would make sense The following patches implement such a toggle, it is disabled by default, so the previous behaviour of not showing quit messages is preserved. Showing who sent a mode change can also be useful, for example, in the event that a user gives +o to some untrusted user, you may want to know who did that. See https://todo.sr.ht/~delthas/senpai/159. I chose to show these at all times, see Runxi Yu's comment on this: > Could we also have a way to access it from the keyboard? > > And to be honest, I'd prefer it to be on the screen all the time > (as opposed to only show when clicked or only show when activated > via the keyboard) but I guess that's a personal preference Cheers! Ferass El Hafidi (3): Optionally show quit and part messages doc/senpai.5.scd: document "quitmessages" option Show mode change sender app.go | 14 ++++++++++++-- config.go | 11 +++++++++++ doc/senpai.5.scd | 3 +++ irc/events.go | 3 +++ irc/session.go | 18 ++++++++++++++++-- 5 files changed, 45 insertions(+), 4 deletions(-) -- 2.45.1
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~delthas/senpai-dev/patches/54214/mbox | git am -3Learn more about email & git
These are not shown by default, enable `quitmessages` in the config file to show them. Also differenciate between a quit and a part by showing an "x" next to the nickname instead of a "-" for a quit. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com> --- app.go | 12 +++++++++++- config.go | 11 +++++++++++ irc/events.go | 2 ++ irc/session.go | 16 ++++++++++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 24546e7..61a7401 100644 --- a/app.go +++ b/app.go @@ -1639,6 +1639,11 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Foreground: app.cfg.Colors.Status, }) body.WriteString(ev.User) + if app.cfg.QuitMessages { + body.WriteString(" (") + body.WriteString(ev.Message) + body.WriteByte(')') + } return ui.Line{ At: ev.Time, Head: "--", @@ -1654,11 +1659,16 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { body.SetStyle(vaxis.Style{ Foreground: ui.ColorRed, }) - body.WriteByte('-') + body.WriteByte('x') body.SetStyle(vaxis.Style{ Foreground: app.cfg.Colors.Status, }) body.WriteString(ev.User) + if app.cfg.QuitMessages { + body.WriteString(" (") + body.WriteString(ev.Message) + body.WriteByte(')') + } return ui.Line{ At: ev.Time, Head: "--", diff --git a/config.go b/config.go index 3b6c40b..69cee97 100644 --- a/config.go +++ b/config.go @@ -108,6 +108,7 @@ type Config struct { ChanColEnabled bool MemberColWidth int MemberColEnabled bool + QuitMessages bool TextMaxWidth int StatusEnabled bool @@ -146,6 +147,7 @@ func Defaults() Config { ChanColEnabled: true, MemberColWidth: 16, MemberColEnabled: true, + QuitMessages: false, TextMaxWidth: 0, StatusEnabled: true, Colors: ui.ConfigColors{ @@ -425,6 +427,15 @@ func unmarshal(filename string, cfg *Config) (err error) { return fmt.Errorf("unknown colors directive %q", child.Name) } } + case "quitmessages": + var quitmessages string + if err := d.ParseParams(&quitmessages); err != nil { + return err + } + + if cfg.QuitMessages, err = strconv.ParseBool(quitmessages); err != nil { + return err + } case "debug": var debug string if err := d.ParseParams(&debug); err != nil { diff --git a/irc/events.go b/irc/events.go index 9bb61ba..716a9c1 100644 --- a/irc/events.go +++ b/irc/events.go @@ -48,12 +48,14 @@ type UserPartEvent struct { User string Channel string Time time.Time + Message string } type UserQuitEvent struct { User string Channels []string Time time.Time + Message string } type UserOnlineEvent struct { diff --git a/irc/session.go b/irc/session.go index 9132e65..b2ac931 100644 --- a/irc/session.go +++ b/irc/session.go @@ -901,8 +901,11 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er } var channel string - if err := msg.ParseParams(&channel); err != nil { - return nil, err + var partmessage string + if len(msg.Params) == 2 { + if err := msg.ParseParams(&channel, &partmessage); err != nil { + return nil, err + } } if playback { @@ -910,6 +913,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er User: msg.Prefix.Name, Channel: channel, Time: msg.TimeOrNow(), + Message: partmessage, }, nil } @@ -982,10 +986,17 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er return nil, errMissingPrefix } + var quitmessage string + + if err := msg.ParseParams(&quitmessage); err != nil { + return nil, err + } + if playback { return UserQuitEvent{ User: msg.Prefix.Name, Time: msg.TimeOrNow(), + Message: quitmessage, }, nil } @@ -1006,6 +1017,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er User: u.Name.Name, Channels: channels, Time: msg.TimeOrNow(), + Message: quitmessage, }, nil } case rplMononline: -- 2.45.1
See previous commit. Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com> --- doc/senpai.5.scd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/senpai.5.scd b/doc/senpai.5.scd index b6a29f9..17331e3 100644 --- a/doc/senpai.5.scd +++ b/doc/senpai.5.scd @@ -153,6 +153,9 @@ pane-widths { *mouse* Enable or disable mouse support. Defaults to true. +*quitmessages* + Enable or disable showing quit and part messages. Defaults to false. + *colors* { ... } Settings for colors of different UI elements. -- 2.45.1
Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com> --- app.go | 2 +- irc/events.go | 1 + irc/session.go | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 61a7401..fb37d23 100644 --- a/app.go +++ b/app.go @@ -1693,7 +1693,7 @@ func (app *App) formatEvent(ev irc.Event) ui.Line { Readable: true, } case irc.ModeChangeEvent: - body := fmt.Sprintf("[%s]", ev.Mode) + body := fmt.Sprintf("[%s] by %s", ev.Mode, ev.Who) // simple mode event: <+/-><mode> <nick> mergeable := len(strings.Split(ev.Mode, " ")) == 2 return ui.Line{ diff --git a/irc/events.go b/irc/events.go index 716a9c1..2fbafd5 100644 --- a/irc/events.go +++ b/irc/events.go @@ -77,6 +77,7 @@ type ModeChangeEvent struct { Channel string Mode string Time time.Time + Who string } type InviteEvent struct { diff --git a/irc/session.go b/irc/session.go index b2ac931..8f0a68c 100644 --- a/irc/session.go +++ b/irc/session.go @@ -1195,6 +1195,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er Channel: channel, Mode: mode, Time: msg.TimeOrNow(), + Who: msg.Prefix.Name, }, nil } @@ -1235,6 +1236,7 @@ func (s *Session) handleMessageRegistered(msg Message, playback bool) (Event, er Channel: c.Name, Mode: mode, Time: msg.TimeOrNow(), + Who: msg.Prefix.Name, }, nil } case "INVITE": -- 2.45.1