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