commit ee83827

Hubert Hirtz  ·  2021-10-23 16:35:00 +0000 UTC
parent 992fcfa
Add support for the INVITE message
3 files changed,  +56, -0
M app.go
M app.go
+24, -0
 1@@ -686,6 +686,30 @@ func (app *App) handleIRCEvent(ev interface{}) {
 2 			HeadColor: tcell.ColorGray,
 3 			Body:      body.StyledString(),
 4 		})
 5+	case irc.InviteEvent:
 6+		var buffer string
 7+		var notify ui.NotifyType
 8+		var body string
 9+		if app.s.IsMe(ev.Invitee) {
10+			buffer = Home
11+			notify = ui.NotifyHighlight
12+			body = fmt.Sprintf("%s invited you to join %s", ev.Inviter, ev.Channel)
13+		} else if app.s.IsMe(ev.Inviter) {
14+			buffer = ev.Channel
15+			notify = ui.NotifyNone
16+			body = fmt.Sprintf("You invited %s to join this channel", ev.Invitee)
17+		} else {
18+			buffer = ev.Channel
19+			notify = ui.NotifyUnread
20+			body = fmt.Sprintf("%s invited %s to join this channel", ev.Inviter, ev.Invitee)
21+		}
22+		app.win.AddLine(buffer, notify, ui.Line{
23+			At:        msg.TimeOrNow(),
24+			Head:      "--",
25+			HeadColor: tcell.ColorGray,
26+			Body:      ui.Styled(body, tcell.StyleDefault.Foreground(tcell.ColorGray)),
27+			Highlight: notify == ui.NotifyHighlight,
28+		})
29 	case irc.MessageEvent:
30 		buffer, line, hlNotification := app.formatMessage(ev)
31 		var notify ui.NotifyType
+6, -0
 1@@ -56,6 +56,12 @@ type ModeChangeEvent struct {
 2 	Mode    string
 3 }
 4 
 5+type InviteEvent struct {
 6+	Inviter string
 7+	Invitee string
 8+	Channel string
 9+}
10+
11 type MessageEvent struct {
12 	User            string
13 	Target          string
+26, -0
 1@@ -863,6 +863,32 @@ func (s *Session) handleRegistered(msg Message) (Event, error) {
 2 				Mode:    strings.Join(msg.Params[1:], " "),
 3 			}, nil
 4 		}
 5+	case "INVITE":
 6+		if msg.Prefix == nil {
 7+			return nil, errMissingPrefix
 8+		}
 9+
10+		var nick, channel string
11+		if err := msg.ParseParams(&nick, &channel); err != nil {
12+			return nil, err
13+		}
14+
15+		return InviteEvent{
16+			Inviter: msg.Prefix.Name,
17+			Invitee: nick,
18+			Channel: channel,
19+		}, nil
20+	case rplInviting:
21+		var nick, channel string
22+		if err := msg.ParseParams(nil, &nick, &channel); err != nil {
23+			return nil, err
24+		}
25+
26+		return InviteEvent{
27+			Inviter: s.nick,
28+			Invitee: nick,
29+			Channel: channel,
30+		}, nil
31 	case "PRIVMSG", "NOTICE":
32 		if msg.Prefix == nil {
33 			return nil, errMissingPrefix