From 2c5872f12039c1ffea9923fd8356ceafc86bcfdb Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 11 Jul 2021 20:45:57 +0200 Subject: Print the channel topic on join Fixes: #45 --- app.go | 20 ++++++++++++++++++++ commands.go | 15 +-------------- irc/events.go | 1 + irc/session.go | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/app.go b/app.go index 24cb2de..bf86aa2 100644 --- a/app.go +++ b/app.go @@ -515,6 +515,9 @@ func (app *App) handleIRCEvent(ev interface{}) { if ev.Requested { app.win.JumpBufferIndex(i) } + if ev.Topic != "" { + app.printTopic(ev.Channel) + } case irc.UserJoinEvent: body := new(ui.StyledStringBuilder) body.Grow(len(ev.User) + 1) @@ -808,3 +811,20 @@ func (app *App) updatePrompt() { } app.win.SetPrompt(prompt) } + +func (app *App) printTopic(buffer string) { + var body string + + topic, who, at := app.s.Topic(buffer) + if who == nil { + body = fmt.Sprintf("Topic: %s", topic) + } else { + body = fmt.Sprintf("Topic (by %s, %s): %s", who, at.Local().Format("Mon Jan 2 15:04:05"), topic) + } + app.win.AddLine(buffer, ui.NotifyNone, ui.Line{ + At: time.Now(), + Head: "--", + HeadColor: tcell.ColorGray, + Body: ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)), + }) +} diff --git a/commands.go b/commands.go index 3f92540..447340d 100644 --- a/commands.go +++ b/commands.go @@ -358,20 +358,7 @@ func commandDoR(app *App, buffer string, args []string) (err error) { func commandDoTopic(app *App, buffer string, args []string) (err error) { if len(args) == 0 { - var body string - - topic, who, at := app.s.Topic(buffer) - if who == nil { - body = fmt.Sprintf("Topic: %s", topic) - } else { - body = fmt.Sprintf("Topic (by %s, %s): %s", who, at.Local().Format("Mon Jan 2 15:04:05"), topic) - } - app.win.AddLine(buffer, ui.NotifyNone, ui.Line{ - At: time.Now(), - Head: "--", - HeadColor: tcell.ColorGray, - Body: ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)), - }) + app.printTopic(buffer) } else { app.s.ChangeTopic(buffer, args[0]) } diff --git a/irc/events.go b/irc/events.go index 0451a80..eeac8fb 100644 --- a/irc/events.go +++ b/irc/events.go @@ -24,6 +24,7 @@ type UserNickEvent struct { type SelfJoinEvent struct { Channel string Requested bool // whether we recently requested to join that channel + Topic string } type UserJoinEvent struct { diff --git a/irc/session.go b/irc/session.go index 33d52fc..d08fb22 100644 --- a/irc/session.go +++ b/irc/session.go @@ -692,6 +692,7 @@ func (s *Session) handleRegistered(msg Message) Event { s.channels[channelCf] = c ev := SelfJoinEvent{ Channel: c.Name, + Topic: c.Topic, } if stamp, ok := s.pendingChannels[channelCf]; ok && time.Now().Sub(stamp) < 5*time.Second { ev.Requested = true -- cgit v1.2.3