diff options
author | Michael Muré <batolettre@gmail.com> | 2022-08-20 10:14:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-20 10:14:09 +0200 |
commit | 58df94d38d754bff4dcca11e2ae4b99326a9a87e (patch) | |
tree | 8701efc87732439f993eb4f1d00585fc419b87ab /entities/bug/timeline.go | |
parent | 5ca686b59751e3c87740b84108c54fc675a074cf (diff) | |
parent | 5511c230b678a181cc596238bf6669428d1b1902 (diff) | |
download | git-bug-58df94d38d754bff4dcca11e2ae4b99326a9a87e.tar.gz |
Merge pull request #852 from MichaelMure/move-around
move {bug,identity} to /entities, move input to /commands
Diffstat (limited to 'entities/bug/timeline.go')
-rw-r--r-- | entities/bug/timeline.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/entities/bug/timeline.go b/entities/bug/timeline.go new file mode 100644 index 00000000..d7f042db --- /dev/null +++ b/entities/bug/timeline.go @@ -0,0 +1,80 @@ +package bug + +import ( + "strings" + + "github.com/MichaelMure/git-bug/entities/identity" + "github.com/MichaelMure/git-bug/entity" + "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/timestamp" +) + +type TimelineItem interface { + // Id return the identifier of the item + Id() entity.Id +} + +// CommentHistoryStep hold one version of a message in the history +type CommentHistoryStep struct { + // The author of the edition, not necessarily the same as the author of the + // original comment + Author identity.Interface + // The new message + Message string + UnixTime timestamp.Timestamp +} + +// CommentTimelineItem is a TimelineItem that holds a Comment and its edition history +type CommentTimelineItem struct { + // id should be the same as in Comment + id entity.Id + Author identity.Interface + Message string + Files []repository.Hash + CreatedAt timestamp.Timestamp + LastEdit timestamp.Timestamp + History []CommentHistoryStep +} + +func NewCommentTimelineItem(comment Comment) CommentTimelineItem { + return CommentTimelineItem{ + id: comment.id, + 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) Id() entity.Id { + return c.id +} + +// 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{ + Author: comment.Author, + Message: comment.Message, + UnixTime: comment.UnixTime, + }) +} + +// Edited say if the comment was edited +func (c *CommentTimelineItem) Edited() bool { + return len(c.History) > 1 +} + +// 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 +} |