-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
item_user.go
143 lines (131 loc) · 4.14 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
133
134
135
136
137
138
139
140
141
142
143
package ui
import (
"bytes"
"fmt"
"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(tv *TutView, data *api.User, main *tview.TextView, controls *tview.Flex, additional string, ut InputUserType) {
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 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 []Control
if ut == InputUserFollowRequest {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserFollowRequestDecide, false))
}
if tv.tut.Client.Me.ID != user.ID {
if relation.Following {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserFollow, false))
} else {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserFollow, true))
}
if relation.Blocking {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserBlock, false))
} else {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserBlock, true))
}
if relation.Muting {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserMute, false))
} else {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserMute, true))
}
if len(urls) > 0 {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserLinks, true))
}
}
if showUserControl {
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserUser, true))
}
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserAvatar, true))
controlItems = append(controlItems, NewControl(tv.tut.Config, tv.tut.Config.Input.UserYank, true))
// Clear controls and only have add and delete for lists.
if ut == InputUserListAdd {
controlItems = []Control{NewControl(tv.tut.Config, tv.tut.Config.Input.ListUserAdd, true)}
} else if ut == InputUserListDelete {
controlItems = []Control{NewControl(tv.tut.Config, tv.tut.Config.Input.ListUserDelete, true)}
}
controls.Clear()
for i, item := range controlItems {
if i < len(controlItems)-1 {
controls.AddItem(NewControlButton(tv, item), item.Len+1, 0, false)
} else {
controls.AddItem(NewControlButton(tv, item), item.Len, 0, false)
}
}
ud := DisplayUserData{
User: u,
Style: tv.tut.Config.Style,
}
var output bytes.Buffer
err := tv.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(tv.tut.Config, tview.Escape(additional)))
}
main.SetText(additional + output.String())
}
}