forked from emersion/neutron
/
labels.go
74 lines (65 loc) · 1.32 KB
/
labels.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
package backend
// Stores labels data.
type LabelsBackend interface {
// List all user's labels.
ListLabels(user string) ([]*Label, error)
// Insert a new label.
InsertLabel(user string, label *Label) (*Label, error)
// Update an existing label.
UpdateLabel(user string, update *LabelUpdate) (*Label, error)
// Delete a label.
DeleteLabel(user, id string) error
}
type LabelType int
const (
LabelMessage LabelType = 1
LabelContact
)
// A message label.
type Label struct {
ID string
Name string
Color string
Display int
Type LabelType
Exclusive int
Order int
}
// System labels
const (
InboxLabel string = "0"
DraftLabel = "1"
SentLabel = "2"
TrashLabel = "3"
SpamLabel = "4"
ArchiveLabel = "6"
StarredLabel = "10"
)
// A request to update a label.
// Fields set to true will be updated with values in Label.
type LabelUpdate struct {
Label *Label
Name bool
Color bool
Display bool
Order bool
}
// Apply this update on a label.
func (update *LabelUpdate) Apply(label *Label) {
updated := update.Label
if updated.ID != label.ID {
panic("Cannot apply update on a label with a different ID")
}
if update.Name {
label.Name = updated.Name
}
if update.Color {
label.Color = updated.Color
}
if update.Display {
label.Display = updated.Display
}
if update.Order {
label.Order = updated.Order
}
}