| 1 |
package backend |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/google/uuid" |
| 5 |
"github.com/henrybear327/go-proton-api" |
| 6 |
) |
| 7 |
|
| 8 |
type label struct { |
| 9 |
labelID string |
| 10 |
parentID string |
| 11 |
name string |
| 12 |
labelType proton.LabelType |
| 13 |
messageIDs map[string]struct{} |
| 14 |
} |
| 15 |
|
| 16 |
func newLabel(labelName, parentID string, labelType proton.LabelType) *label { |
| 17 |
return &label{ |
| 18 |
labelID: uuid.NewString(), |
| 19 |
parentID: parentID, |
| 20 |
name: labelName, |
| 21 |
labelType: labelType, |
| 22 |
messageIDs: make(map[string]struct{}), |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
func (label *label) toLabel(labels map[string]*label) proton.Label { |
| 27 |
var path []string |
| 28 |
|
| 29 |
for labelID := label.labelID; labelID != ""; labelID = labels[labelID].parentID { |
| 30 |
path = append([]string{labels[labelID].name}, path...) |
| 31 |
} |
| 32 |
|
| 33 |
return proton.Label{ |
| 34 |
ID: label.labelID, |
| 35 |
ParentID: label.parentID, |
| 36 |
Name: label.name, |
| 37 |
Path: path, |
| 38 |
Type: label.labelType, |
| 39 |
} |
| 40 |
} |