forked from ProtonMail/go-proton-api
/
label.go
40 lines (34 loc) · 866 Bytes
/
label.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
package backend
import (
"github.com/google/uuid"
"github.com/pushrbx/go-proton-api"
)
type label struct {
labelID string
parentID string
name string
labelType proton.LabelType
messageIDs map[string]struct{}
}
func newLabel(labelName, parentID string, labelType proton.LabelType) *label {
return &label{
labelID: uuid.NewString(),
parentID: parentID,
name: labelName,
labelType: labelType,
messageIDs: make(map[string]struct{}),
}
}
func (label *label) toLabel(labels map[string]*label) proton.Label {
var path []string
for labelID := label.labelID; labelID != ""; labelID = labels[labelID].parentID {
path = append([]string{labels[labelID].name}, path...)
}
return proton.Label{
ID: label.labelID,
ParentID: label.parentID,
Name: label.name,
Path: path,
Type: label.labelType,
}
}