-
Notifications
You must be signed in to change notification settings - Fork 1
/
member.go
83 lines (67 loc) · 2.5 KB
/
member.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
package pkgo
import (
"time"
"github.com/google/uuid"
)
// Member holds information for a specific system member.
// Fields set to private are empty.
type Member struct {
ID string `json:"id"`
UUID uuid.UUID `json:"uuid"`
Name string `json:"name,omitempty"`
DisplayName string `json:"display_name,omitempty"`
Color Color `json:"color,omitempty"`
Birthday Birthday `json:"birthday,omitempty"`
Pronouns string `json:"pronouns,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Banner string `json:"banner,omitempty"`
Description string `json:"description,omitempty"`
Created time.Time `json:"created"`
ProxyTags []ProxyTag `json:"proxy_tags,omitempty"`
KeepProxy bool `json:"keep_proxy"`
Privacy *MemberPrivacy `json:"privacy,omitempty"`
}
// MemberPrivacy is a member privacy object.
type MemberPrivacy struct {
Visibility Privacy `json:"visibility,omitempty"`
NamePrivacy Privacy `json:"name_privacy,omitempty"`
DescriptionPrivacy Privacy `json:"description_privacy,omitempty"`
BirthdayPrivacy Privacy `json:"birthday_privacy,omitempty"`
PronounPrivacy Privacy `json:"pronoun_privacy,omitempty"`
AvatarPrivacy Privacy `json:"avatar_privacy,omitempty"`
MetadataPrivacy Privacy `json:"metadata_privacy,omitempty"`
}
// Validate will validate the member object.
// If any of the fields have invalid values, it returns an InvalidError.
func (m Member) Validate() error {
if len(m.Name) > 50 || len(m.DisplayName) > 50 ||
len(m.Description) > 1000 || len(m.Pronouns) > 100 {
return &InvalidError{"Name", m.Name}
}
if len(m.DisplayName) > 50 {
return &InvalidError{"DisplayName", m.DisplayName}
}
if len(m.Description) > 1000 {
return &InvalidError{"Description", m.Description}
}
if len(m.Pronouns) > 100 {
return &InvalidError{"Pronouns", m.Pronouns}
}
// Privacy fields can only be "public", "private", or null
for _, f := range []Privacy{m.Privacy.Visibility, m.Privacy.NamePrivacy, m.Privacy.DescriptionPrivacy, m.Privacy.AvatarPrivacy, m.Privacy.BirthdayPrivacy, m.Privacy.PronounPrivacy, m.Privacy.MetadataPrivacy} {
if f != "private" && f != "public" && f != "" {
return &InvalidError{"Privacy", string(f)}
}
}
if !m.Color.IsValid() {
return &InvalidError{"Color", string(m.Color)}
}
return nil
}
// String returns the member's displayed name--either DisplayName if one is set, otherwise Name.
func (m Member) String() string {
if m.DisplayName != "" {
return m.DisplayName
}
return m.Name
}