-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebar.go
More file actions
64 lines (61 loc) · 1.36 KB
/
Copy pathsidebar.go
File metadata and controls
64 lines (61 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"github.com/jroimartin/gocui"
)
func updateSidebar() {
ui.Update(func(g *gocui.Gui) error {
sidebar.Clear()
fmt.Fprintln(sidebar, "Chats:")
var users []chat
database.Order("telegram_user_name asc").Find(&users)
for _, user := range users {
marker := ""
if user.hasUnread() {
marker = "*"
}
linked := "?"
if user.isLinked() {
linked = ""
}
current := " "
if user.isCurrent() {
current = ">"
}
fmt.Fprintf(sidebar, "%s %s%s%s\n", current, user.TelegramUserName, linked, marker)
}
fmt.Fprintln(sidebar, "")
fmt.Fprintln(sidebar, "Crews:")
var crews []crew
database.Find(&crews)
var activeCrew crew
for _, crew := range crews {
current := fmt.Sprintf("%d", crew.ID)
if crew.isCurrent() {
current = ">"
activeCrew = crew
}
fmt.Fprintf(sidebar, "%s %s (%s)\n", current, crew.Name, crew.Code)
}
if activeCrewID != 0 {
fmt.Fprintln(sidebar, "")
fmt.Fprintln(sidebar, "Contacts:")
for _, contact := range activeCrew.fetchContacts() {
current := " "
if contact.isCurrent() {
current = ">"
}
linked := " "
if contact.CrewID != 0 {
linked = "|"
}
unread := ""
if contact.numContactUnread() > 0 {
unread = "*"
}
fmt.Fprintf(sidebar, "%s%s%s%s\n", current, linked, contact.Name, unread)
}
}
return nil
})
}