diff options
Diffstat (limited to 'worker/types')
-rw-r--r-- | worker/types/thread.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/worker/types/thread.go b/worker/types/thread.go index 9f59e9e6..60ecc7ce 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "sort" + + "git.sr.ht/~rjarry/aerc/logging" ) type Thread struct { @@ -48,6 +50,33 @@ func (t *Thread) Walk(walkFn NewThreadWalkFn) error { return err } +// Root returns the root thread of the thread tree +func (t *Thread) Root() *Thread { + if t == nil { + return nil + } + var iter *Thread + for iter = t; iter.Parent != nil; iter = iter.Parent { + } + return iter +} + +// Uids returns all associated uids for the given thread and its children +func (t *Thread) Uids() []uint32 { + if t == nil { + return nil + } + uids := make([]uint32, 0) + err := t.Walk(func(node *Thread, _ int, _ error) error { + uids = append(uids, node.Uid) + return nil + }) + if err != nil { + logging.Errorf("walk to collect uids failed: %w", err) + } + return uids +} + func (t *Thread) String() string { if t == nil { return "<nil>" |