~taiite/senpai

2c5872f12039c1ffea9923fd8356ceafc86bcfdb — delthas 11 months ago 2c7bc6a
Print the channel topic on join

Fixes: #45
4 files changed, 23 insertions(+), 14 deletions(-)

M app.go
M commands.go
M irc/events.go
M irc/session.go
M app.go => app.go +20 -0
@@ 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)),
	})
}

M commands.go => commands.go +1 -14
@@ 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])
	}

M irc/events.go => irc/events.go +1 -0
@@ 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 {

M irc/session.go => irc/session.go +1 -0
@@ 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