commit 300bf7a

delthas  ·  2022-10-04 10:19:38 +0000 UTC
parent 09b45e5
Prevnet highlighting on notices, drop unknown CTCP
1 files changed,  +23, -9
M app.go
M app.go
+23, -9
 1@@ -848,6 +848,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 		})
 3 	case irc.MessageEvent:
 4 		buffer, line, notification := app.formatMessage(s, ev)
 5+		if line.IsZero() {
 6+			break
 7+		}
 8 		if buffer != "" && !s.IsChannel(buffer) {
 9 			if _, added := app.win.AddBuffer(netID, "", buffer); added {
10 				app.monitor[netID][buffer] = struct{}{}
11@@ -1256,17 +1259,32 @@ func (app *App) formatEvent(ev irc.Event) ui.Line {
12 func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer string, line ui.Line, notification ui.NotifyType) {
13 	isFromSelf := s.IsMe(ev.User)
14 	isToSelf := s.IsMe(ev.Target)
15-	isHighlight := app.isHighlight(s, ev.Content)
16-	isAction := strings.HasPrefix(ev.Content, "\x01ACTION")
17+	isHighlight := ev.TargetIsChannel && app.isHighlight(s, ev.Content)
18 	isQuery := !ev.TargetIsChannel && ev.Command == "PRIVMSG"
19 	isNotice := ev.Command == "NOTICE"
20 
21+	content := strings.TrimSuffix(ev.Content, "\x01")
22+	content = strings.TrimRightFunc(content, unicode.IsSpace)
23+
24+	isAction := false
25+	if strings.HasPrefix(ev.Content, "\x01") {
26+		parts := strings.SplitN(ev.Content[1:], " ", 2)
27+		if len(parts) < 2 {
28+			return
29+		}
30+		switch parts[0] {
31+		case "ACTION":
32+			isAction = true
33+		default:
34+			return
35+		}
36+		content = parts[1]
37+	}
38+
39 	if !ev.TargetIsChannel && isNotice {
40 		curNetID, curBuffer := app.win.CurrentBuffer()
41 		if curNetID == s.NetID() {
42 			buffer = curBuffer
43-		} else {
44-			isHighlight = true
45 		}
46 	} else if isToSelf {
47 		buffer = ev.User
48@@ -1291,11 +1309,6 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
49 		headColor = ui.IdentColor(app.cfg.Colors.Nicks, head)
50 	}
51 
52-	content := strings.TrimSuffix(ev.Content, "\x01")
53-	content = strings.TrimRightFunc(content, unicode.IsSpace)
54-	if isAction {
55-		content = content[7:]
56-	}
57 	var body ui.StyledStringBuilder
58 	if isNotice {
59 		color := ui.IdentColor(app.cfg.Colors.Nicks, ev.User)
60@@ -1309,6 +1322,7 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
61 		body.SetStyle(tcell.StyleDefault.Foreground(color))
62 		body.WriteString(ev.User)
63 		body.SetStyle(tcell.StyleDefault)
64+		body.WriteString(" ")
65 		body.WriteStyledString(ui.IRCString(content))
66 	} else {
67 		body.WriteStyledString(ui.IRCString(content))