2018-09-29 21:41:19 +03:00
|
|
|
package bug
|
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
import (
|
|
|
|
"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
|
|
|
|
Hash() (git.Hash, error)
|
|
|
|
}
|
|
|
|
|
2018-09-30 12:00:39 +03:00
|
|
|
type CommentHistoryStep struct {
|
|
|
|
Message string
|
|
|
|
UnixTime Timestamp
|
|
|
|
}
|
|
|
|
|
2018-09-29 21:41:19 +03:00
|
|
|
// CreateTimelineItem replace a Create operation in the Timeline and hold its edition history
|
|
|
|
type CreateTimelineItem struct {
|
2018-09-30 12:00:39 +03:00
|
|
|
CommentTimelineItem
|
2018-09-29 21:41:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
|
|
|
|
return &CreateTimelineItem{
|
2018-09-30 12:00:39 +03:00
|
|
|
CommentTimelineItem: CommentTimelineItem{
|
|
|
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
|
|
|
|
type CommentTimelineItem struct {
|
2018-09-30 12:00:39 +03:00
|
|
|
hash git.Hash
|
|
|
|
Author Person
|
|
|
|
Message string
|
|
|
|
Files []git.Hash
|
|
|
|
CreatedAt Timestamp
|
|
|
|
LastEdit Timestamp
|
|
|
|
History []CommentHistoryStep
|
2018-09-29 21:41:19 +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
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommentTimelineItem) Hash() (git.Hash, error) {
|
|
|
|
return c.hash, nil
|
|
|
|
}
|
|
|
|
|
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{
|
|
|
|
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
|
|
|
}
|