aboutsummaryrefslogtreecommitdiff
path: root/ui/view-main.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-03-26 17:22:47 +0300
committerTulir Asokan <tulir@maunium.net>2018-03-26 17:22:47 +0300
commitb31d96881432ebb1d4918ae970fabfd6362e1186 (patch)
tree565340e18ce1f9107f52285215a53765b4afaf38 /ui/view-main.go
parent6095638fbb0a39fa240a135cf47e54ce5681ee9d (diff)
Show notifications and highlights in room list. Fixes #8
Diffstat (limited to 'ui/view-main.go')
-rw-r--r--ui/view-main.go43
1 files changed, 42 insertions, 1 deletions
diff --git a/ui/view-main.go b/ui/view-main.go
index 94d09ab..a037ea0 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -28,6 +28,9 @@ import (
"maunium.net/go/gomatrix"
"maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/interface"
+ "maunium.net/go/gomuks/matrix/pushrules"
+ "maunium.net/go/gomuks/matrix/rooms"
+ "maunium.net/go/gomuks/notification"
"maunium.net/go/gomuks/ui/debug"
"maunium.net/go/gomuks/ui/types"
"maunium.net/go/gomuks/ui/widget"
@@ -239,6 +242,10 @@ func (view *MainView) MouseEventHandler(roomView *widget.RoomView, event *tcell.
msgView.AddScrollOffset(-WheelScrollOffsetDiff)
view.parent.Render()
+
+ if msgView.ScrollOffset == 0 {
+ roomView.Room.MarkRead()
+ }
default:
debug.Print("Mouse event received:", event.Buttons(), event.Modifiers(), x, y)
return event
@@ -263,7 +270,11 @@ func (view *MainView) SwitchRoom(roomIndex int) {
}
view.currentRoomIndex = roomIndex % len(view.roomIDs)
view.roomView.SwitchToPage(view.CurrentRoomID())
- view.roomList.SetSelected(view.rooms[view.CurrentRoomID()].Room)
+ roomView := view.rooms[view.CurrentRoomID()]
+ if roomView.MessageView().ScrollOffset == 0 {
+ roomView.Room.MarkRead()
+ }
+ view.roomList.SetSelected(roomView.Room)
view.gmx.App().SetFocus(view)
view.parent.Render()
}
@@ -367,6 +378,36 @@ func (view *MainView) SetTyping(room string, users []string) {
}
}
+func sendNotification(room *rooms.Room, sender, text string, critical bool) {
+ if room.GetTitle() != sender {
+ sender = fmt.Sprintf("%s (%s)", sender, room.GetTitle())
+ }
+ notification.Send(sender, text, critical)
+}
+
+func (view *MainView) NotifyMessage(room *rooms.Room, message *types.Message, should pushrules.PushActionArrayShould) {
+ isCurrent := room.ID == view.CurrentRoomID()
+ if !isCurrent {
+ room.HasNewMessages = true
+ }
+ shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender != view.config.Session.UserID
+ if shouldNotify {
+ sendNotification(room, message.Sender, message.Text, should.Highlight)
+ if !isCurrent {
+ room.UnreadMessages++
+ }
+ }
+ if should.Highlight {
+ message.TextColor = tcell.ColorYellow
+ if !isCurrent {
+ room.Highlighted = true
+ }
+ }
+ if should.PlaySound {
+ // TODO play sound
+ }
+}
+
func (view *MainView) AddServiceMessage(roomView *widget.RoomView, text string) {
message := roomView.NewMessage("", "*", "gomuks.service", text, time.Now())
message.TextColor = tcell.ColorGray