forked from RasmusLindroth/tut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_user.go
132 lines (121 loc) · 3.67 KB
/
item_user.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package ui
import (
"bytes"
"fmt"
"strings"
"time"
"github.com/RasmusLindroth/tut/api"
"github.com/RasmusLindroth/tut/config"
"github.com/RasmusLindroth/tut/util"
"github.com/rivo/tview"
)
type User struct {
Username string
Account string
DisplayName string
Locked bool
CreatedAt time.Time
FollowersCount int64
FollowingCount int64
StatusCount int64
Note string
URL string
Avatar string
AvatarStatic string
Header string
HeaderStatic string
Fields []Field
Bot bool
//Emojis []Emoji
//Moved *Account `json:"moved"`
}
type Field struct {
Name string
Value string
VerifiedAt time.Time
}
type DisplayUserData struct {
User User
Style config.Style
}
func drawUser(tut *Tut, data *api.User, main *tview.TextView, controls *tview.TextView, additional string, fr bool) {
user := data.Data
relation := data.Relation
showUserControl := true
u := User{
Username: tview.Escape(user.Username),
Account: tview.Escape(user.Acct),
DisplayName: tview.Escape(user.DisplayName),
Locked: user.Locked,
CreatedAt: user.CreatedAt,
FollowersCount: user.FollowersCount,
FollowingCount: user.FollowingCount,
StatusCount: user.StatusesCount,
URL: user.URL,
Avatar: user.Avatar,
AvatarStatic: user.AvatarStatic,
Header: user.Header,
HeaderStatic: user.HeaderStatic,
Bot: user.Bot,
}
var controlsS string
var urls []util.URL
fields := []Field{}
u.Note, urls = util.CleanHTML(user.Note)
for _, f := range user.Fields {
value, fu := util.CleanHTML(f.Value)
fields = append(fields, Field{
Name: tview.Escape(f.Name),
Value: tview.Escape(value),
VerifiedAt: f.VerifiedAt,
})
urls = append(urls, fu...)
}
u.Fields = fields
var controlItems []string
if fr {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserFollowRequestDecide, false))
}
if tut.Client.Me.ID != user.ID {
if relation.Following {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserFollow, false))
} else {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserFollow, true))
}
if relation.Blocking {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserBlock, false))
} else {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserBlock, true))
}
if relation.Muting {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserMute, false))
} else {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserMute, true))
}
if len(urls) > 0 {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserLinks, true))
}
}
if showUserControl {
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserUser, true))
}
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserAvatar, true))
controlItems = append(controlItems, config.ColorFromKey(tut.Config, tut.Config.Input.UserYank, true))
controlsS = strings.Join(controlItems, " ")
ud := DisplayUserData{
User: u,
Style: tut.Config.Style,
}
var output bytes.Buffer
err := tut.Config.Templates.User.ExecuteTemplate(&output, "user.tmpl", ud)
if err != nil {
panic(err)
}
if main != nil {
if additional != "" {
additional = fmt.Sprintf("%s\n\n", config.SublteText(tut.Config, additional))
}
main.SetText(additional + output.String())
}
controls.SetText(controlsS)
}