Don't send notifications for current room
This commit is contained in:
parent
e0298521c6
commit
d684187f42
@ -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) {
|
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()
|
isCurrent := room.ID == view.CurrentRoomID()
|
||||||
if !isCurrent {
|
// Whether or not the terminal window is focused.
|
||||||
room.HasNewMessages = true
|
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
|
shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
|
||||||
if shouldNotify {
|
|
||||||
shouldPlaySound := should.PlaySound && should.SoundName == "default"
|
if !isCurrent {
|
||||||
sendNotification(room, message.Sender, message.Text, should.Highlight, shouldPlaySound)
|
// The message is not in the current room, show new message status in room list.
|
||||||
if !isCurrent {
|
room.HasNewMessages = true
|
||||||
|
room.Highlighted = should.Highlight || room.Highlighted
|
||||||
|
if shouldNotify {
|
||||||
room.UnreadMessages++
|
room.UnreadMessages++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if should.Highlight {
|
|
||||||
message.TextColor = tcell.ColorYellow
|
if shouldNotify && !isFocused {
|
||||||
if !isCurrent {
|
// Push rules say notify and the terminal is not focused, send desktop notification.
|
||||||
room.Highlighted = true
|
shouldPlaySound := should.PlaySound && should.SoundName == "default"
|
||||||
}
|
sendNotification(room, message.Sender, message.Text, should.Highlight, shouldPlaySound)
|
||||||
}
|
}
|
||||||
if should.PlaySound {
|
|
||||||
// TODO play sound
|
if should.Highlight {
|
||||||
|
// Message is highlight, set color.
|
||||||
|
message.TextColor = tcell.ColorYellow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user