aboutsummaryrefslogtreecommitdiffstats
path: root/bug/timeline.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-30 11:00:39 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-30 11:03:42 +0200
commit037f5bf50b2bb2b020620413d186b6acf47a0b61 (patch)
tree6639ac6f8c53bcc4a27660ea92faff46974e98b2 /bug/timeline.go
parentd450c7a883876e0f5356fb5cb54109a0a2a77dfd (diff)
downloadgit-bug-037f5bf50b2bb2b020620413d186b6acf47a0b61.tar.gz
timeline: various minor improvements
Diffstat (limited to 'bug/timeline.go')
-rw-r--r--bug/timeline.go81
1 files changed, 53 insertions, 28 deletions
diff --git a/bug/timeline.go b/bug/timeline.go
index 0f79958b..d734e18b 100644
--- a/bug/timeline.go
+++ b/bug/timeline.go
@@ -1,50 +1,67 @@
package bug
-import "github.com/MichaelMure/git-bug/util/git"
+import (
+ "github.com/MichaelMure/git-bug/util/git"
+)
type TimelineItem interface {
// Hash return the hash of the item
Hash() (git.Hash, error)
}
+type CommentHistoryStep struct {
+ Message string
+ UnixTime Timestamp
+}
+
// CreateTimelineItem replace a Create operation in the Timeline and hold its edition history
type CreateTimelineItem struct {
- hash git.Hash
- History []Comment
+ CommentTimelineItem
}
func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
return &CreateTimelineItem{
- hash: hash,
- History: []Comment{
- comment,
+ 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,
+ },
+ },
},
}
}
-func (c *CreateTimelineItem) Hash() (git.Hash, error) {
- return c.hash, nil
-}
-
-func (c *CreateTimelineItem) LastState() Comment {
- if len(c.History) == 0 {
- panic("no history yet")
- }
-
- return c.History[len(c.History)-1]
-}
-
// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
type CommentTimelineItem struct {
- hash git.Hash
- History []Comment
+ hash git.Hash
+ Author Person
+ Message string
+ Files []git.Hash
+ CreatedAt Timestamp
+ LastEdit Timestamp
+ History []CommentHistoryStep
}
func NewCommentTimelineItem(hash git.Hash, comment Comment) *CommentTimelineItem {
return &CommentTimelineItem{
- hash: hash,
- History: []Comment{
- comment,
+ 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,
+ },
},
}
}
@@ -53,10 +70,18 @@ func (c *CommentTimelineItem) Hash() (git.Hash, error) {
return c.hash, nil
}
-func (c *CommentTimelineItem) LastState() Comment {
- if len(c.History) == 0 {
- panic("no history yet")
- }
+// 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,
+ })
+}
- return c.History[len(c.History)-1]
+// Edited say if the comment was edited
+func (c *CommentTimelineItem) Edited() bool {
+ return len(c.History) > 1
}