File: label.go

package info (click to toggle)
golang-github-henrybear327-go-proton-api 1.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,088 kB
  • sloc: sh: 55; makefile: 26
file content (40 lines) | stat: -rw-r--r-- 871 bytes parent folder | download
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/henrybear327/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,
	}
}