Fix notifications about own messages

This commit is contained in:
Tulir Asokan 2018-05-16 21:42:07 +03:00
parent a8a4c72d14
commit 512ca88804
4 changed files with 11 additions and 3 deletions

View File

@ -117,4 +117,6 @@ type Message interface {
SetState(state MessageState)
State() MessageState
SenderID() string
}

View File

@ -30,7 +30,6 @@ type UIMessage interface {
Buffer() []tstring.TString
Height() int
SenderID() string
RealSender() string
RegisterMatrix(matrix ifc.MatrixContainer)
}

View File

@ -34,6 +34,10 @@ func (meta *BasicMeta) Sender() string {
return meta.BSender
}
func (meta *BasicMeta) SenderID() string {
return meta.BSender
}
// SenderColor returns the color the name of the sender should be shown in.
func (meta *BasicMeta) SenderColor() tcell.Color {
return meta.BSenderColor

View File

@ -429,6 +429,10 @@ func sendNotification(room *rooms.Room, sender, text string, critical, sound boo
}
func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, should pushrules.PushActionArrayShould) {
view.roomList.Bump(room)
if message.SenderID() == view.config.Session.UserID {
return
}
// Whether or not the room where the message came is the currently shown room.
isCurrent := room == view.roomList.SelectedRoom()
// Whether or not the terminal window is focused.
@ -436,7 +440,7 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul
isFocused := time.Now().Add(-5 * time.Second).Before(view.lastFocusTime)
// 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
if !isCurrent || !isFocused {
// The message is not in the current room, show new message status in room list.
@ -452,7 +456,6 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul
}
message.SetIsHighlight(should.Highlight)
view.roomList.Bump(room)
}
func (view *MainView) InitialSyncDone() {