Fix People tag

This commit is contained in:
Tulir Asokan 2018-04-25 07:01:00 +03:00
parent 3de07ad550
commit 576bab9e2e
2 changed files with 15 additions and 7 deletions

View File

@ -58,7 +58,7 @@ func NewRoomList() *RoomList {
return &RoomList{ return &RoomList{
Box: tview.NewBox(), Box: tview.NewBox(),
items: make(map[string][]*rooms.Room), items: make(map[string][]*rooms.Room),
tags: []string{"m.favourite", "im.vector.fake.direct", "", "m.lowpriority"}, tags: []string{"m.favourite", "net.maunium.gomuks.fake.direct", "", "m.lowpriority"},
mainTextColor: tcell.ColorWhite, mainTextColor: tcell.ColorWhite,
selectedTextColor: tcell.ColorWhite, selectedTextColor: tcell.ColorWhite,
@ -102,6 +102,9 @@ func (list *RoomList) CheckTag(tag string) {
} }
func (list *RoomList) AddToTag(tag string, room *rooms.Room) { func (list *RoomList) AddToTag(tag string, room *rooms.Room) {
if tag == "" && len(room.GetMembers()) == 2 {
tag = "net.maunium.gomuks.fake.direct"
}
items, ok := list.items[tag] items, ok := list.items[tag]
if !ok { if !ok {
list.items[tag] = []*rooms.Room{room} list.items[tag] = []*rooms.Room{room}
@ -214,7 +217,7 @@ func (list *RoomList) Clear() {
func (list *RoomList) SetSelected(tag string, room *rooms.Room) { func (list *RoomList) SetSelected(tag string, room *rooms.Room) {
list.selected = room list.selected = room
list.selectedTag = tag list.selectedTag = tag
debug.Print("Selecting", room.GetTitle(), "in", tag) debug.Print("Selecting", room.GetTitle(), "in", list.GetTagDisplayName(tag))
} }
func (list *RoomList) HasSelected() bool { func (list *RoomList) HasSelected() bool {
@ -356,10 +359,8 @@ func (list *RoomList) GetTagDisplayName(tag string) string {
return "Favorites" return "Favorites"
case tag == "m.lowpriority": case tag == "m.lowpriority":
return "Low Priority" return "Low Priority"
case tag == "im.vector.fake.direct": case tag == "net.maunium.gomuks.fake.direct":
return "People" return "People"
case strings.HasPrefix(tag, "m."):
return strings.Title(strings.Replace(tag[len("m."):], "_", " ", -1))
case strings.HasPrefix(tag, "u."): case strings.HasPrefix(tag, "u."):
return tag[len("u."):] return tag[len("u."):]
case !nsRegex.MatchString(tag): case !nsRegex.MatchString(tag):
@ -386,7 +387,12 @@ func (list *RoomList) Draw(screen tcell.Screen) {
// Draw the list items. // Draw the list items.
for _, tag := range list.tags { for _, tag := range list.tags {
items := list.items[tag] items := list.items[tag]
widget.WriteLine(screen, tview.AlignLeft, list.GetTagDisplayName(tag), x, y, width, tcell.StyleDefault.Underline(true).Bold(true)) tagDisplayName := list.GetTagDisplayName(tag)
if len(tagDisplayName) == 0 {
continue
}
widget.WriteLine(screen, tview.AlignLeft, tagDisplayName, x, y, width, tcell.StyleDefault.Underline(true).Bold(true))
y++ y++
for i := len(items) - 1; i >= 0; i-- { for i := len(items) - 1; i >= 0; i-- {
item := items[i] item := items[i]

View File

@ -67,6 +67,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
mainView.AddItem(mainView.roomList, 25, 0, false) mainView.AddItem(mainView.roomList, 25, 0, false)
mainView.AddItem(widget.NewBorder(), 1, 0, false) mainView.AddItem(widget.NewBorder(), 1, 0, false)
mainView.AddItem(mainView.roomView, 0, 1, true) mainView.AddItem(mainView.roomView, 0, 1, true)
mainView.BumpFocus()
ui.mainView = mainView ui.mainView = mainView
@ -398,6 +399,7 @@ func sendNotification(room *rooms.Room, sender, text string, critical, sound boo
if room.GetTitle() != sender { if room.GetTitle() != sender {
sender = fmt.Sprintf("%s (%s)", sender, room.GetTitle()) sender = fmt.Sprintf("%s (%s)", sender, room.GetTitle())
} }
debug.Printf("Sending notification with body \"%s\" from %s in room ID %s (critical=%v, sound=%v)", text, sender, room.ID, critical, sound)
notification.Send(sender, text, critical, sound) notification.Send(sender, text, critical, sound)
} }
@ -405,7 +407,7 @@ func (view *MainView) NotifyMessage(room *rooms.Room, message ifc.Message, shoul
// Whether or not the room where the message came is the currently shown room. // Whether or not the room where the message came is the currently shown room.
isCurrent := room == view.roomList.SelectedRoom() isCurrent := room == view.roomList.SelectedRoom()
// Whether or not the terminal window is focused. // Whether or not the terminal window is focused.
isFocused := view.lastFocusTime.Add(30 * time.Second).Before(time.Now()) isFocused := time.Now().Add(-30 * time.Second).Before(view.lastFocusTime)
// Whether or not the push rules say this message should be notified about. // 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) && message.Sender() != view.config.Session.UserID