aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2020-02-22 00:03:57 +0200
committerTulir Asokan <tulir@maunium.net>2020-02-22 00:03:57 +0200
commit442fdac4d5b949e556e94b0be53f2208709e8bf3 (patch)
treef63cb447525cdc15a4d733f857aefc82a0c9a7b7 /ui
parent032a83d70bec5b87605e04c755c678ec01a0de11 (diff)
Enable lazy loading of members
Diffstat (limited to 'ui')
-rw-r--r--ui/member-list.go38
-rw-r--r--ui/view-main.go11
2 files changed, 45 insertions, 4 deletions
diff --git a/ui/member-list.go b/ui/member-list.go
index a96436d..b607a32 100644
--- a/ui/member-list.go
+++ b/ui/member-list.go
@@ -17,6 +17,7 @@
package ui
import (
+ "math"
"sort"
"strings"
@@ -40,6 +41,7 @@ func NewMemberList() *MemberList {
type memberListItem struct {
mautrix.Member
PowerLevel int
+ Sigil rune
UserID string
Color tcell.Color
}
@@ -64,11 +66,35 @@ func (rml roomMemberList) Swap(i, j int) {
func (ml *MemberList) Update(data map[string]*mautrix.Member, levels *mautrix.PowerLevels) *MemberList {
ml.list = make(roomMemberList, len(data))
i := 0
+ highestLevel := math.MinInt32
+ count := 0
+ for _, level := range levels.Users {
+ if level > highestLevel {
+ highestLevel = level
+ count = 1
+ } else if level == highestLevel {
+ count++
+ }
+ }
for userID, member := range data {
+ level := levels.GetUserLevel(userID)
+ sigil := ' '
+ if level == highestLevel && count == 1 {
+ sigil = '~'
+ } else if level > levels.StateDefault() {
+ sigil = '&'
+ } else if level >= levels.Ban() {
+ sigil = '@'
+ } else if level >= levels.Kick() || level >= levels.Redact() {
+ sigil = '%'
+ } else if level > levels.UsersDefault {
+ sigil = '+'
+ }
ml.list[i] = &memberListItem{
Member: *member,
UserID: userID,
- PowerLevel: levels.GetUserLevel(userID),
+ PowerLevel: level,
+ Sigil: sigil,
Color: widget.GetHashColor(userID),
}
i++
@@ -79,17 +105,21 @@ func (ml *MemberList) Update(data map[string]*mautrix.Member, levels *mautrix.Po
func (ml *MemberList) Draw(screen mauview.Screen) {
width, _ := screen.Size()
+ sigilStyle := tcell.StyleDefault.Background(tcell.ColorGreen).Foreground(tcell.ColorWhite)
for y, member := range ml.list {
+ if member.Sigil != ' ' {
+ screen.SetCell(0, y, sigilStyle, member.Sigil)
+ }
if member.Membership == "invite" {
- widget.WriteLineSimpleColor(screen, member.Displayname, 1, y, member.Color)
- screen.SetCell(0, y, tcell.StyleDefault, '(')
+ screen.SetCell(1, y, tcell.StyleDefault, '(')
if sw := runewidth.StringWidth(member.Displayname); sw < width-1 {
screen.SetCell(sw+1, y, tcell.StyleDefault, ')')
} else {
screen.SetCell(width-1, y, tcell.StyleDefault, ')')
}
+ widget.WriteLineSimpleColor(screen, member.Displayname, 2, y, member.Color)
} else {
- widget.WriteLineSimpleColor(screen, member.Displayname, 0, y, member.Color)
+ widget.WriteLineSimpleColor(screen, member.Displayname, 1, y, member.Color)
}
}
}
diff --git a/ui/view-main.go b/ui/view-main.go
index 507333a..30fa982 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -276,6 +276,17 @@ func (view *MainView) switchRoom(tag string, room *rooms.Room, lock bool) {
msgView.initialHistoryLoaded = true
go view.LoadHistory(room.ID)
}
+ if !room.MembersFetched {
+ go func() {
+ err := view.matrix.FetchMembers(room)
+ if err != nil {
+ debug.Print("Error fetching members:", err)
+ return
+ }
+ roomView.UpdateUserList()
+ view.parent.Render()
+ }()
+ }
}
func (view *MainView) addRoomPage(room *rooms.Room) *RoomView {