aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--matrix/matrix.go2
-rw-r--r--matrix/rooms/room.go4
-rw-r--r--ui/room-list.go24
-rw-r--r--ui/view-main.go4
4 files changed, 30 insertions, 4 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go
index eb0eea5..87013ac 100644
--- a/matrix/matrix.go
+++ b/matrix/matrix.go
@@ -255,7 +255,7 @@ func (c *Container) HandlePushRules(evt *gomatrix.Event) {
// HandleTag is the event handler for the m.tag account data event.
func (c *Container) HandleTag(evt *gomatrix.Event) {
- debug.Print("Received updated tags")
+ debug.Print("Received updated tags for", evt.RoomID)
dat, _ := json.MarshalIndent(&evt.Content, "", " ")
debug.Print(string(dat))
}
diff --git a/matrix/rooms/room.go b/matrix/rooms/room.go
index 61415a9..7b4a8b5 100644
--- a/matrix/rooms/room.go
+++ b/matrix/rooms/room.go
@@ -20,6 +20,7 @@ import (
"fmt"
"sort"
"sync"
+ "time"
"maunium.net/go/gomatrix"
)
@@ -52,6 +53,9 @@ type Room struct {
// a notificationless message like bot notices.
HasNewMessages bool
+ Tags []string
+ LastReceivedMessage time.Time
+
// MXID -> Member cache calculated from membership events.
memberCache map[string]*Member
// The first non-SessionUserID member in the room. Calculated at
diff --git a/ui/room-list.go b/ui/room-list.go
index 7637d4f..cad1b5a 100644
--- a/ui/room-list.go
+++ b/ui/room-list.go
@@ -19,6 +19,7 @@ package ui
import (
"fmt"
"strconv"
+ "time"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/widget"
@@ -29,7 +30,9 @@ import (
type RoomList struct {
*tview.Box
- items []*rooms.Room
+ // The list of rooms, in reverse order.
+ items []*rooms.Room
+ // The selected room.
selected *rooms.Room
// The item main text color.
@@ -61,7 +64,18 @@ func (list *RoomList) Contains(roomID string) bool {
}
func (list *RoomList) Add(room *rooms.Room) {
- list.items = append(list.items, room)
+ list.items = append(list.items, nil)
+ insertAt := len(list.items) - 1
+ for i := 0; i < len(list.items)-1; i++ {
+ if list.items[i].LastReceivedMessage.After(room.LastReceivedMessage) {
+ insertAt = i
+ break
+ }
+ }
+ for i := len(list.items) - 1; i > insertAt; i-- {
+ list.items[i] = list.items[i-1]
+ }
+ list.items[insertAt] = room
}
func (list *RoomList) Remove(room *rooms.Room) {
@@ -91,6 +105,7 @@ func (list *RoomList) Bump(room *rooms.Room) {
}
}
list.items[len(list.items)-1] = room
+ room.LastReceivedMessage = time.Now()
}
func (list *RoomList) Clear() {
@@ -150,7 +165,10 @@ func (list *RoomList) Index(room *rooms.Room) int {
}
func (list *RoomList) Get(n int) *rooms.Room {
- return list.items[len(list.items)-1-(n%len(list.items))]
+ if n < 0 || n > len(list.items)-1 {
+ return nil
+ }
+ return list.items[len(list.items)-1-n]
}
// Draw draws this primitive onto the screen.
diff --git a/ui/view-main.go b/ui/view-main.go
index e9350e7..d1af09d 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -249,6 +249,10 @@ func (view *MainView) MouseEventHandler(roomView *RoomView, event *tcell.EventMo
}
func (view *MainView) SwitchRoom(room *rooms.Room) {
+ if room == nil {
+ return
+ }
+
view.roomView.SwitchToPage(room.ID)
roomView := view.rooms[room.ID]
if roomView.MessageView().ScrollOffset == 0 {