commit 19e0026

delthas  ·  2021-10-31 12:04:31 +0000 UTC
parent 88663c1
Don't show notifications when receiving a message from self
1 files changed,  +12, -12
M app.go
M app.go
+12, -12
 1@@ -733,15 +733,9 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
 2 			Highlight: notify == ui.NotifyHighlight,
 3 		})
 4 	case irc.MessageEvent:
 5-		buffer, line, hlNotification := app.formatMessage(s, ev)
 6-		var notify ui.NotifyType
 7-		if hlNotification {
 8-			notify = ui.NotifyHighlight
 9-		} else {
10-			notify = ui.NotifyUnread
11-		}
12-		app.win.AddLine(netID, buffer, notify, line)
13-		if hlNotification {
14+		buffer, line, notification := app.formatMessage(s, ev)
15+		app.win.AddLine(netID, buffer, notification, line)
16+		if notification == ui.NotifyHighlight {
17 			app.notifyHighlight(buffer, ev.User, line.Body.String())
18 		}
19 		if !s.IsChannel(msg.Params[0]) && !s.IsMe(ev.User) {
20@@ -925,8 +919,8 @@ func (app *App) completions(cursorIdx int, text []rune) []ui.Completion {
21 // It computes three things:
22 // - which buffer the message must be added to,
23 // - the UI line,
24-// - whether senpai must trigger the "on-highlight" command.
25-func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer string, line ui.Line, hlNotification bool) {
26+// - what kind of notification senpai should send.
27+func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer string, line ui.Line, notification ui.NotifyType) {
28 	isFromSelf := s.IsMe(ev.User)
29 	isHighlight := app.isHighlight(s, ev.Content)
30 	isAction := strings.HasPrefix(ev.Content, "\x01ACTION")
31@@ -947,7 +941,13 @@ func (app *App) formatMessage(s *irc.Session, ev irc.MessageEvent) (buffer strin
32 	}
33 
34 	hlLine := ev.TargetIsChannel && isHighlight && !isFromSelf
35-	hlNotification = (isHighlight || isQuery) && !isFromSelf
36+	if isFromSelf {
37+		notification = ui.NotifyNone
38+	} else if isHighlight || isQuery {
39+		notification = ui.NotifyHighlight
40+	} else {
41+		notification = ui.NotifyUnread
42+	}
43 
44 	head := ev.User
45 	headColor := tcell.ColorWhite