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
12type CommentHistoryStep struct {
13 Message string
14 UnixTime Timestamp
15}
16
17// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
18type CommentTimelineItem struct {
19 hash git.Hash
20 Author Person
21 Message string
22 Files []git.Hash
23 CreatedAt Timestamp
24 LastEdit Timestamp
25 History []CommentHistoryStep
26}
27
28func NewCommentTimelineItem(hash git.Hash, comment Comment) CommentTimelineItem {
29 return CommentTimelineItem{
30 hash: hash,
31 Author: comment.Author,
32 Message: comment.Message,
33 Files: comment.Files,
34 CreatedAt: comment.UnixTime,
35 LastEdit: comment.UnixTime,
36 History: []CommentHistoryStep{
37 {
38 Message: comment.Message,
39 UnixTime: comment.UnixTime,
40 },
41 },
42 }
43}
44
45func (c *CommentTimelineItem) Hash() git.Hash {
46 return c.hash
47}
48
49// Append will append a new comment in the history and update the other values
50func (c *CommentTimelineItem) Append(comment Comment) {
51 c.Message = comment.Message
52 c.Files = comment.Files
53 c.LastEdit = comment.UnixTime
54 c.History = append(c.History, CommentHistoryStep{
55 Message: comment.Message,
56 UnixTime: comment.UnixTime,
57 })
58}
59
60// Edited say if the comment was edited
61func (c *CommentTimelineItem) Edited() bool {
62 return len(c.History) > 1
63}