aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-26 20:55:52 +0300
committerTulir Asokan <tulir@maunium.net>2018-03-26 20:59:58 +0300
commitd684187f4294d876bf12244cd5a832221ac156dc (patch)
treeb79d03932669cf0f780eabbe93e7cbd2e04d2a73 /ui
parente0298521c6c12c5f347431bfad5b6a4d7ab8b465 (diff)
Don't send notifications for current room
Diffstat (limited to 'ui')
-rw-r--r--ui/view-main.go28
1 files changed, 17 insertions, 11 deletions
diff --git a/ui/view-main.go b/ui/view-main.go
index a35c35e..fd05492 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -386,26 +386,32 @@ func sendNotification(room *rooms.Room, sender, text string, critical, sound boo
}
func (view *MainView) NotifyMessage(room *rooms.Room, message *types.Message, should pushrules.PushActionArrayShould) {
+ // Whether or not the room where the message came is the currently shown room.
isCurrent := room.ID == view.CurrentRoomID()
+ // Whether or not the terminal window is focused.
+ isFocused := view.lastFocusTime.Add(30 * time.Second).Before(time.Now())
+
+ // Whether or not the push rules say this message should be notified about.
+ shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
+
if !isCurrent {
+ // The message is not in the current room, show new message status in room list.
room.HasNewMessages = true
+ room.Highlighted = should.Highlight || room.Highlighted
+ if shouldNotify {
+ room.UnreadMessages++
+ }
}
- shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
- if shouldNotify {
+
+ if shouldNotify && !isFocused {
+ // Push rules say notify and the terminal is not focused, send desktop notification.
shouldPlaySound := should.PlaySound && should.SoundName == "default"
sendNotification(room, message.Sender, message.Text, should.Highlight, shouldPlaySound)
- if !isCurrent {
- room.UnreadMessages++
- }
}
+
if should.Highlight {
+ // Message is highlight, set color.
message.TextColor = tcell.ColorYellow
- if !isCurrent {
- room.Highlighted = true
- }
- }
- if should.PlaySound {
- // TODO play sound
}
}