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{
Box: tview.NewBox(),
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,
selectedTextColor: tcell.ColorWhite,
@ -102,6 +102,9 @@ func (list *RoomList) CheckTag(tag string) {
}
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]
if !ok {
list.items[tag] = []*rooms.Room{room}
@ -214,7 +217,7 @@ func (list *RoomList) Clear() {
func (list *RoomList) SetSelected(tag string, room *rooms.Room) {
list.selected = room
list.selectedTag = tag
debug.Print("Selecting", room.GetTitle(), "in", tag)
debug.Print("Selecting", room.GetTitle(), "in", list.GetTagDisplayName(tag))
}
func (list *RoomList) HasSelected() bool {
@ -356,10 +359,8 @@ func (list *RoomList) GetTagDisplayName(tag string) string {
return "Favorites"
case tag == "m.lowpriority":
return "Low Priority"
case tag == "im.vector.fake.direct":
case tag == "net.maunium.gomuks.fake.direct":
return "People"
case strings.HasPrefix(tag, "m."):
return strings.Title(strings.Replace(tag[len("m."):], "_", " ", -1))
case strings.HasPrefix(tag, "u."):
return tag[len("u."):]
case !nsRegex.MatchString(tag):
@ -386,7 +387,12 @@ func (list *RoomList) Draw(screen tcell.Screen) {
// Draw the list items.
for _, tag := range list.tags {
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++
for i := len(items) - 1; i >= 0; 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(widget.NewBorder(), 1, 0, false)
mainView.AddItem(mainView.roomView, 0, 1, true)
mainView.BumpFocus()
ui.mainView = mainView
@ -398,6 +399,7 @@ func sendNotification(room *rooms.Room, sender, text string, critical, sound boo
if room.GetTitle() != sender {
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)
}
@ -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.
isCurrent := room == view.roomList.SelectedRoom()
// 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.
shouldNotify := (should.Notify || !should.NotifySpecified) && message.Sender() != view.config.Session.UserID