From 5eac8d603e8807f7d4be58a4a7b03862a8c90df2 Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Mon, 21 Feb 2022 00:18:41 +0100 Subject: [PATCH] thread: add method to append new node implement a method function for a *types.Thread receiver to append a new node to its linked list. Signed-off-by: Koni Marti --- worker/types/thread.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/worker/types/thread.go b/worker/types/thread.go index 09f9dbb..18b31e9 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -16,6 +16,19 @@ type Thread struct { Deleted bool // if this flag is set the message was deleted } +func (t *Thread) AddChild(child *Thread) { + if t.FirstChild == nil { + t.FirstChild = child + } else { + var iter *Thread + for iter = t.FirstChild; iter.NextSibling != nil; iter = iter.NextSibling { + } + child.PrevSibling = iter + iter.NextSibling = child + } + child.Parent = t +} + func (t *Thread) Walk(walkFn NewThreadWalkFn) error { err := newWalk(t, walkFn, 0, nil) if err == ErrSkipThread {