aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-24 22:58:30 +0300
committerGitHub <noreply@github.com>2018-04-24 22:58:30 +0300
commit7026ed99a3ef4071a35e74d2d5f9026f6848be92 (patch)
tree33332880db2cbdaeabaeb4e1ddbf94a3f15686a3 /ui
parent49cd74c548e3baf259fce9270af3ecca5bdb625e (diff)
parentd7d654e2ec0a1d001f936b1575a3e6af3973a874 (diff)
Merge pull request #33 from tulir/initial-sync
Use initial sync data instead of fetching room list, state, history, etc manually
Diffstat (limited to 'ui')
-rw-r--r--ui/message-view.go6
-rw-r--r--ui/messages/textbase.go14
-rw-r--r--ui/room-list.go57
-rw-r--r--ui/view-main.go29
4 files changed, 65 insertions, 41 deletions
diff --git a/ui/message-view.go b/ui/message-view.go
index ca03e73..f2fb72f 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -183,7 +183,8 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction ifc.Messag
} else if oldMsg != nil {
view.replaceBuffer(oldMsg, message)
} else {
- view.replaceBuffer(message, message)
+ debug.Print("Unexpected AddMessage() call: Direction is not append or prepend, but message is new.")
+ debug.PrintStack()
}
view.messageIDs[message.ID()] = message
@@ -232,7 +233,8 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
}
if start == -1 {
- debug.Print("Called replaceBuffer() with message that was not in the buffer:", original)
+ debug.Print("Called replaceBuffer() with message that was not in the buffer:", original.ID())
+ debug.PrintStack()
view.appendBuffer(new)
return
}
diff --git a/ui/messages/textbase.go b/ui/messages/textbase.go
index 0960a57..f44d5d5 100644
--- a/ui/messages/textbase.go
+++ b/ui/messages/textbase.go
@@ -72,8 +72,18 @@ func (msg *BaseTextMessage) calculateBufferWithText(text tstring.TString, width
}
matches := boundaryPattern.FindAllStringIndex(extract.String(), -1)
- if len(matches) > 0 {
- extract = extract[:matches[len(matches)-1][1]]
+ if len(matches) == 0 {
+ continue
+ }
+
+ match := matches[len(matches)-1]
+ if len(match) < 2 {
+ continue
+ }
+
+ until := match[1]
+ if until < len(extract) {
+ extract = extract[:until]
}
}
msg.buffer = append(msg.buffer, extract)
diff --git a/ui/room-list.go b/ui/room-list.go
index a70fd68..9444313 100644
--- a/ui/room-list.go
+++ b/ui/room-list.go
@@ -23,6 +23,7 @@ import (
"strings"
"time"
+ "maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell"
@@ -57,6 +58,7 @@ func NewRoomList() *RoomList {
return &RoomList{
Box: tview.NewBox(),
items: make(map[string][]*rooms.Room),
+ tags: []string{"m.favourite", "im.vector.fake.direct", "", "m.lowpriority"},
mainTextColor: tcell.ColorWhite,
selectedTextColor: tcell.ColorWhite,
@@ -86,16 +88,17 @@ func (list *RoomList) CheckTag(tag string) {
items, ok := list.items[tag]
- if len(items) == 0 {
+ if ok && len(items) == 0 {
delete(list.items, tag)
ok = false
}
if ok && index == -1 {
list.tags = append(list.tags, tag)
- } else if index != -1 {
+ } /* TODO this doesn't work properly
+ else if index != -1 {
list.tags = append(list.tags[0:index], list.tags[index+1:]...)
- }
+ }*/
}
func (list *RoomList) AddToTag(tag string, room *rooms.Room) {
@@ -210,7 +213,8 @@ func (list *RoomList) Clear() {
func (list *RoomList) SetSelected(tag string, room *rooms.Room) {
list.selected = room
- list.selectedTag = ""
+ list.selectedTag = tag
+ debug.Print("Selecting", room.GetTitle(), "in", tag)
}
func (list *RoomList) HasSelected() bool {
@@ -229,7 +233,7 @@ func (list *RoomList) First() (string, *rooms.Room) {
for _, tag := range list.tags {
items := list.items[tag]
if len(items) > 0 {
- return tag, items[0]
+ return tag, items[len(items)-1]
}
}
return "", nil
@@ -240,7 +244,7 @@ func (list *RoomList) Last() (string, *rooms.Room) {
tag := list.tags[tagIndex]
items := list.items[tag]
if len(items) > 0 {
- return tag, items[len(items)-1]
+ return tag, items[0]
}
}
return "", nil
@@ -264,17 +268,19 @@ func (list *RoomList) Previous() (string, *rooms.Room) {
items := list.items[list.selectedTag]
index := list.indexInTag(list.selectedTag, list.selected)
- if index == len(items)-1 {
+ if index == -1 {
+ return list.First()
+ } else if index == len(items)-1 {
tagIndex := list.IndexTag(list.selectedTag)
- tagIndex++
- for ; tagIndex < len(list.tags); tagIndex++ {
- nextTag := list.tags[tagIndex]
- nextTagItems := list.items[nextTag]
- if len(nextTagItems) > 0 {
- return nextTag, nextTagItems[0]
+ tagIndex--
+ for ; tagIndex >= 0; tagIndex-- {
+ prevTag := list.tags[tagIndex]
+ prevTagItems := list.items[prevTag]
+ if len(prevTagItems) > 0 {
+ return prevTag, prevTagItems[0]
}
}
- return list.First()
+ return list.Last()
}
return list.selectedTag, items[index+1]
}
@@ -288,17 +294,19 @@ func (list *RoomList) Next() (string, *rooms.Room) {
items := list.items[list.selectedTag]
index := list.indexInTag(list.selectedTag, list.selected)
- if index == 0 {
+ if index == -1 {
+ return list.Last()
+ } else if index == 0 {
tagIndex := list.IndexTag(list.selectedTag)
- tagIndex--
- for ; tagIndex >= 0; tagIndex-- {
- prevTag := list.tags[tagIndex]
- prevTagItems := list.items[prevTag]
- if len(prevTagItems) > 0 {
- return prevTag, prevTagItems[len(prevTagItems)-1]
+ tagIndex++
+ for ; tagIndex < len(list.tags); tagIndex++ {
+ nextTag := list.tags[tagIndex]
+ nextTagItems := list.items[nextTag]
+ if len(nextTagItems) > 0 {
+ return nextTag, nextTagItems[len(nextTagItems)-1]
}
}
- return list.Last()
+ return list.First()
}
return list.selectedTag, items[index-1]
}
@@ -332,6 +340,8 @@ func (list *RoomList) Get(n int) (string, *rooms.Room) {
// Tag items
n -= len(items)
+ // Tag footer
+ n--
}
return "", nil
}
@@ -346,6 +356,8 @@ func (list *RoomList) GetTagDisplayName(tag string) string {
return "Favorites"
case tag == "m.lowpriority":
return "Low Priority"
+ case tag == "im.vector.fake.direct":
+ return "People"
case strings.HasPrefix(tag, "m."):
return strings.Title(strings.Replace(tag[len("m."):], "_", " ", -1))
case strings.HasPrefix(tag, "u."):
@@ -420,5 +432,6 @@ func (list *RoomList) Draw(screen tcell.Screen) {
break
}
}
+ y++
}
}
diff --git a/ui/view-main.go b/ui/view-main.go
index ba3a55b..d20fed3 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -173,7 +173,7 @@ func (view *MainView) KeyEventHandler(roomView *RoomView, key *tcell.EventKey) *
msgView := roomView.MessageView()
if msgView.IsAtTop() && (k == tcell.KeyPgUp || k == tcell.KeyUp) {
- go view.LoadHistory(roomView.Room.ID, false)
+ go view.LoadHistory(roomView.Room.ID)
}
switch k {
@@ -215,7 +215,7 @@ func (view *MainView) MouseEventHandler(roomView *RoomView, event *tcell.EventMo
switch event.Buttons() {
case tcell.WheelUp:
if msgView.IsAtTop() {
- go view.LoadHistory(roomView.Room.ID, false)
+ go view.LoadHistory(roomView.Room.ID)
} else {
msgView.AddScrollOffset(WheelScrollOffsetDiff)
@@ -293,11 +293,9 @@ func (view *MainView) addRoomPage(room *rooms.Room) {
view.roomView.AddPage(room.ID, roomView, true, false)
roomView.UpdateUserList()
- count, err := roomView.LoadHistory(view.matrix, view.config.HistoryDir)
+ _, err := roomView.LoadHistory(view.matrix, view.config.HistoryDir)
if err != nil {
debug.Printf("Failed to load history of %s: %v", roomView.Room.GetTitle(), err)
- } else if count <= 0 {
- go view.LoadHistory(room.ID, true)
}
}
}
@@ -314,18 +312,25 @@ func (view *MainView) GetRoom(roomID string) ifc.RoomView {
func (view *MainView) AddRoom(roomID string) {
if view.roomList.Contains(roomID) {
+ debug.Print("Add aborted", roomID)
return
}
+ debug.Print("Adding", roomID)
room := view.matrix.GetRoom(roomID)
view.roomList.Add(room)
view.addRoomPage(room)
+ if !view.roomList.HasSelected() {
+ view.SwitchRoom(view.roomList.First())
+ }
}
func (view *MainView) RemoveRoom(roomID string) {
roomView := view.GetRoom(roomID)
if roomView == nil {
+ debug.Print("Remove aborted", roomID)
return
}
+ debug.Print("Removing", roomID)
view.roomList.Remove(roomView.MxRoom())
view.SwitchRoom(view.roomList.Selected())
@@ -336,12 +341,11 @@ func (view *MainView) RemoveRoom(roomID string) {
view.parent.Render()
}
-func (view *MainView) SetRooms(roomIDs []string) {
+func (view *MainView) SetRooms(rooms map[string]*rooms.Room) {
view.roomList.Clear()
view.roomView.Clear()
view.rooms = make(map[string]*RoomView)
- for _, roomID := range roomIDs {
- room := view.matrix.GetRoom(roomID)
+ for _, room := range rooms {
view.roomList.Add(room)
view.addRoomPage(room)
}
@@ -425,7 +429,7 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul
view.roomList.Bump(room)
}
-func (view *MainView) LoadHistory(room string, initial bool) {
+func (view *MainView) LoadHistory(room string) {
defer debug.Recover()
roomView := view.rooms[room]
@@ -446,12 +450,7 @@ func (view *MainView) LoadHistory(room string, initial bool) {
return
}
- if initial {
- batch = view.config.Session.NextBatch
- debug.Print("Loading initial history for", room)
- } else {
- debug.Print("Loading more history for", room, "starting from", batch)
- }
+ debug.Print("Fetching history for", room, "starting from", batch)
history, prevBatch, err := view.matrix.GetHistory(roomView.Room.ID, batch, 50)
if err != nil {
roomView.AddServiceMessage("Failed to fetch history")