commit 2c5872f

delthas  ·  2021-07-11 18:45:57 +0000 UTC
parent 2c7bc6a
Print the channel topic on join

Fixes: #45
4 files changed,  +23, -14
M app.go
M app.go
+20, -0
 1@@ -515,6 +515,9 @@ func (app *App) handleIRCEvent(ev interface{}) {
 2 		if ev.Requested {
 3 			app.win.JumpBufferIndex(i)
 4 		}
 5+		if ev.Topic != "" {
 6+			app.printTopic(ev.Channel)
 7+		}
 8 	case irc.UserJoinEvent:
 9 		body := new(ui.StyledStringBuilder)
10 		body.Grow(len(ev.User) + 1)
11@@ -808,3 +811,20 @@ func (app *App) updatePrompt() {
12 	}
13 	app.win.SetPrompt(prompt)
14 }
15+
16+func (app *App) printTopic(buffer string) {
17+	var body string
18+
19+	topic, who, at := app.s.Topic(buffer)
20+	if who == nil {
21+		body = fmt.Sprintf("Topic: %s", topic)
22+	} else {
23+		body = fmt.Sprintf("Topic (by %s, %s): %s", who, at.Local().Format("Mon Jan 2 15:04:05"), topic)
24+	}
25+	app.win.AddLine(buffer, ui.NotifyNone, ui.Line{
26+		At:        time.Now(),
27+		Head:      "--",
28+		HeadColor: tcell.ColorGray,
29+		Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
30+	})
31+}
+1, -14
 1@@ -358,20 +358,7 @@ func commandDoR(app *App, buffer string, args []string) (err error) {
 2 
 3 func commandDoTopic(app *App, buffer string, args []string) (err error) {
 4 	if len(args) == 0 {
 5-		var body string
 6-
 7-		topic, who, at := app.s.Topic(buffer)
 8-		if who == nil {
 9-			body = fmt.Sprintf("Topic: %s", topic)
10-		} else {
11-			body = fmt.Sprintf("Topic (by %s, %s): %s", who, at.Local().Format("Mon Jan 2 15:04:05"), topic)
12-		}
13-		app.win.AddLine(buffer, ui.NotifyNone, ui.Line{
14-			At:        time.Now(),
15-			Head:      "--",
16-			HeadColor: tcell.ColorGray,
17-			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
18-		})
19+		app.printTopic(buffer)
20 	} else {
21 		app.s.ChangeTopic(buffer, args[0])
22 	}
+1, -0
1@@ -24,6 +24,7 @@ type UserNickEvent struct {
2 type SelfJoinEvent struct {
3 	Channel   string
4 	Requested bool // whether we recently requested to join that channel
5+	Topic     string
6 }
7 
8 type UserJoinEvent struct {
+1, -0
1@@ -692,6 +692,7 @@ func (s *Session) handleRegistered(msg Message) Event {
2 			s.channels[channelCf] = c
3 			ev := SelfJoinEvent{
4 				Channel: c.Name,
5+				Topic:   c.Topic,
6 			}
7 			if stamp, ok := s.pendingChannels[channelCf]; ok && time.Now().Sub(stamp) < 5*time.Second {
8 				ev.Requested = true