aboutsummaryrefslogtreecommitdiffstats
path: root/bug/timeline.go
blob: 0f79958b15e4fa98e4b7b9292db9e90403b5b11f (plain) (blame)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package bug

import "github.com/MichaelMure/git-bug/util/git"

type TimelineItem interface {
	// Hash return the hash of the item
	Hash() (git.Hash, error)
}

// CreateTimelineItem replace a Create operation in the Timeline and hold its edition history
type CreateTimelineItem struct {
	hash    git.Hash
	History []Comment
}

func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
	return &CreateTimelineItem{
		hash: hash,
		History: []Comment{
			comment,
		},
	}
}

func (c *CreateTimelineItem) Hash() (git.Hash, error) {
	return c.hash, nil
}

func (c *CreateTimelineItem) LastState() Comment {
	if len(c.History) == 0 {
		panic("no history yet")
	}

	return c.History[len(c.History)-1]
}

// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
type CommentTimelineItem struct {
	hash    git.Hash
	History []Comment
}

func NewCommentTimelineItem(hash git.Hash, comment Comment) *CommentTimelineItem {
	return &CommentTimelineItem{
		hash: hash,
		History: []Comment{
			comment,
		},
	}
}

func (c *CommentTimelineItem) Hash() (git.Hash, error) {
	return c.hash, nil
}

func (c *CommentTimelineItem) LastState() Comment {
	if len(c.History) == 0 {
		panic("no history yet")
	}

	return c.History[len(c.History)-1]
}