aboutsummaryrefslogtreecommitdiffstats
path: root/bug/timeline.go
blob: d734e18b622841a08819cfcf0e7aa7c4eeaa600b (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package bug

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

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

type CommentHistoryStep struct {
	Message  string
	UnixTime Timestamp
}

// CreateTimelineItem replace a Create operation in the Timeline and hold its edition history
type CreateTimelineItem struct {
	CommentTimelineItem
}

func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
	return &CreateTimelineItem{
		CommentTimelineItem: CommentTimelineItem{
			hash:      hash,
			Author:    comment.Author,
			Message:   comment.Message,
			Files:     comment.Files,
			CreatedAt: comment.UnixTime,
			LastEdit:  comment.UnixTime,
			History: []CommentHistoryStep{
				{
					Message:  comment.Message,
					UnixTime: comment.UnixTime,
				},
			},
		},
	}
}

// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
type CommentTimelineItem struct {
	hash      git.Hash
	Author    Person
	Message   string
	Files     []git.Hash
	CreatedAt Timestamp
	LastEdit  Timestamp
	History   []CommentHistoryStep
}

func NewCommentTimelineItem(hash git.Hash, comment Comment) *CommentTimelineItem {
	return &CommentTimelineItem{
		hash:      hash,
		Author:    comment.Author,
		Message:   comment.Message,
		Files:     comment.Files,
		CreatedAt: comment.UnixTime,
		LastEdit:  comment.UnixTime,
		History: []CommentHistoryStep{
			{
				Message:  comment.Message,
				UnixTime: comment.UnixTime,
			},
		},
	}
}

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

// Append will append a new comment in the history and update the other values
func (c *CommentTimelineItem) Append(comment Comment) {
	c.Message = comment.Message
	c.Files = comment.Files
	c.LastEdit = comment.UnixTime
	c.History = append(c.History, CommentHistoryStep{
		Message:  comment.Message,
		UnixTime: comment.UnixTime,
	})
}

// Edited say if the comment was edited
func (c *CommentTimelineItem) Edited() bool {
	return len(c.History) > 1
}