aboutsummaryrefslogtreecommitdiffstats
path: root/bug/timeline.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-30 11:10:03 +0200
committerGitHub <noreply@github.com>2018-09-30 11:10:03 +0200
commitd71bb7dd7632780cf5aad5fda84027fa03a9d0f0 (patch)
treedba6c3c0bab18f41e21cd36a9fe05d1d27a574d4 /bug/timeline.go
parent8fdd6bf99c111c3756056e87ffd9209875ac5c1f (diff)
parentbad9cda969b49bf1bce6799056476ac4684892df (diff)
downloadgit-bug-d71bb7dd7632780cf5aad5fda84027fa03a9d0f0.tar.gz
Merge pull request #54 from MichaelMure/editablecomment
Core support for editable comments
Diffstat (limited to 'bug/timeline.go')
-rw-r--r--bug/timeline.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/bug/timeline.go b/bug/timeline.go
new file mode 100644
index 00000000..d734e18b
--- /dev/null
+++ b/bug/timeline.go
@@ -0,0 +1,87 @@
+package bug
+
+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 {
+ CommentTimelineItem
+}
+
+func NewCreateTimelineItem(hash git.Hash, comment Comment) *CreateTimelineItem {
+ return &CreateTimelineItem{
+ 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,
+ },
+ },
+ },
+ }
+}
+
+// CommentTimelineItem replace a Comment in the Timeline and hold its edition history
+type CommentTimelineItem struct {
+ 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,
+ 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 *CommentTimelineItem) Hash() (git.Hash, error) {
+ return c.hash, nil
+}
+
+// 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,
+ })
+}
+
+// Edited say if the comment was edited
+func (c *CommentTimelineItem) Edited() bool {
+ return len(c.History) > 1
+}