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