1package bug
2
3import (
4 "github.com/MichaelMure/git-bug/util/git"
5)
6
7type TimelineItem interface {
8 // Hash return the hash of the item
9 Hash() git.Hash
10}
11
12// CommentHistoryStep hold one version of a message in the history
13type CommentHistoryStep struct {
14 // The author of the edition, not necessarily the same as the author of the
15 // original comment
16 Author Person
17 // The new message
18 Message string
19 UnixTime Timestamp
20}
21
22// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
23type CommentTimelineItem struct {
24 hash git.Hash
25 Author Person
26 Message string
27 Files []git.Hash
28 CreatedAt Timestamp
29 LastEdit Timestamp
30 History []CommentHistoryStep
31}
32
33func NewCommentTimelineItem(hash git.Hash, comment Comment) CommentTimelineItem {
34 return CommentTimelineItem{
35 hash: hash,
36 Author: comment.Author,
37 Message: comment.Message,
38 Files: comment.Files,
39 CreatedAt: comment.UnixTime,
40 LastEdit: comment.UnixTime,
41 History: []CommentHistoryStep{
42 {
43 Message: comment.Message,
44 UnixTime: comment.UnixTime,
45 },
46 },
47 }
48}
49
50func (c *CommentTimelineItem) Hash() git.Hash {
51 return c.hash
52}
53
54// Append will append a new comment in the history and update the other values
55func (c *CommentTimelineItem) Append(comment Comment) {
56 c.Message = comment.Message
57 c.Files = comment.Files
58 c.LastEdit = comment.UnixTime
59 c.History = append(c.History, CommentHistoryStep{
60 Author: comment.Author,
61 Message: comment.Message,
62 UnixTime: comment.UnixTime,
63 })
64}
65
66// Edited say if the comment was edited
67func (c *CommentTimelineItem) Edited() bool {
68 return len(c.History) > 1
69}