2018-09-29 21:41:19 +03:00
|
|
|
package bug
|
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
import (
|
2018-12-23 23:46:47 +03:00
|
|
|
"strings"
|
|
|
|
|
2018-11-21 20:56:12 +03:00
|
|
|
"github.com/MichaelMure/git-bug/identity"
|
2018-09-30 12:00:39 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/git"
|
|
|
|
)
|
2018-09-29 21:41:19 +03:00
|
|
|
|
|
|
|
type TimelineItem interface {
|
|
|
|
// Hash return the hash of the item
|
2018-09-30 18:15:54 +03:00
|
|
|
Hash() git.Hash
|
2018-09-29 21:41:19 +03:00
|
|
|
}
|
|
|
|
|
2018-12-23 19:55:41 +03:00
|
|
|
// CommentHistoryStep hold one version of a message in the history
|
2018-09-30 12:00:39 +03:00
|
|
|
type CommentHistoryStep struct {
|
2018-10-01 22:47:12 +03:00
|
|
|
// The author of the edition, not necessarily the same as the author of the
|
|
|
|
// original comment
|
2018-11-21 20:56:12 +03:00
|
|
|
Author identity.Interface
|
2018-10-01 22:47:12 +03:00
|
|
|
// The new message
|
2018-09-30 12:00:39 +03:00
|
|
|
Message string
|
|
|
|
UnixTime Timestamp
|
|
|
|
}
|
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history
|
2018-09-29 21:41:19 +03:00
|
|
|
type CommentTimelineItem struct {
|
2018-09-30 12:00:39 +03:00
|
|
|
hash git.Hash
|
2018-11-21 20:56:12 +03:00
|
|
|
Author identity.Interface
|
2018-09-30 12:00:39 +03:00
|
|
|
Message string
|
|
|
|
Files []git.Hash
|
|
|
|
CreatedAt Timestamp
|
|
|
|
LastEdit Timestamp
|
|
|
|
History []CommentHistoryStep
|
2018-09-29 21:41:19 +03:00
|
|
|
}
|
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
func NewCommentTimelineItem(hash git.Hash, comment Comment) CommentTimelineItem {
|
|
|
|
return CommentTimelineItem{
|
2018-09-30 12:00:39 +03:00
|
|
|
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,
|
|
|
|
},
|
2018-09-29 21:41:19 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-30 18:15:54 +03:00
|
|
|
func (c *CommentTimelineItem) Hash() git.Hash {
|
|
|
|
return c.hash
|
2018-09-29 21:41:19 +03:00
|
|
|
}
|
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
// 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{
|
2018-10-02 00:34:45 +03:00
|
|
|
Author: comment.Author,
|
2018-09-30 12:00:39 +03:00
|
|
|
Message: comment.Message,
|
|
|
|
UnixTime: comment.UnixTime,
|
|
|
|
})
|
|
|
|
}
|
2018-09-29 21:41:19 +03:00
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
// Edited say if the comment was edited
|
|
|
|
func (c *CommentTimelineItem) Edited() bool {
|
|
|
|
return len(c.History) > 1
|
2018-09-29 21:41:19 +03:00
|
|
|
}
|
2018-12-23 23:46:47 +03:00
|
|
|
|
|
|
|
// MessageIsEmpty return true is the message is empty or only made of spaces
|
|
|
|
func (c *CommentTimelineItem) MessageIsEmpty() bool {
|
|
|
|
return len(strings.TrimSpace(c.Message)) == 0
|
|
|
|
}
|