-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd-select.go
More file actions
67 lines (60 loc) · 1.3 KB
/
cmd-select.go
File metadata and controls
67 lines (60 loc) · 1.3 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
65
66
67
package main
import (
"fmt"
)
type selectCmd struct{}
func (selectCmd) Command() string {
return "select"
}
func (selectCmd) Description() string {
return "switches the current chat"
}
func (selectCmd) Help(_ []string) {
fmt.Fprintln(outputView, "No help available")
}
func (selectCmd) Execute(args []string) error {
if len(args) != 1 {
return nil
}
if args[0] == "_" {
activeChatID = 0
updateSidebar()
outputView.SetOrigin(0, 0)
outputView.SetCursor(0, 0)
outputView.Clear()
output(func(print printer) {
print("Back to the machine room")
})
return nil
}
var user chat
var count uint
database.Model(&chat{}).Where("telegram_user_name = ?", args[0]).First(&user).Count(&count)
if count == 0 {
output(func(print printer) {
print("No chat with that name present")
})
} else {
activeContactID = 0
activeChatID = user.ID
if user.isLinked() {
crew := user.FetchCrew()
activeCrewID = crew.ID
}
outputView.SetOrigin(0, 0)
outputView.SetCursor(0, 0)
outputView.Clear() //when switching, we clear the output.
messages := user.fetchMessages()
lastOne := len(messages)
firstOne := lastOne - 50
if firstOne < 0 {
firstOne = 0
}
toPrint := messages[firstOne:lastOne]
for _, msg := range toPrint {
msg.print(outputView)
}
updateSidebar()
}
return nil
}