1package operations
2
3import (
4 "github.com/MichaelMure/git-bug/bug"
5 "time"
6)
7
8var _ bug.Operation = AddCommentOperation{}
9
10type AddCommentOperation struct {
11 bug.OpBase
12 Message string
13 Author bug.Person
14 Time int64
15}
16
17func NewAddCommentOp(author bug.Person, message string) AddCommentOperation {
18 return AddCommentOperation{
19 OpBase: bug.OpBase{OperationType: bug.ADD_COMMENT},
20 Message: message,
21 Author: author,
22 Time: time.Now().Unix(),
23 }
24}
25
26func (op AddCommentOperation) Apply(snapshot bug.Snapshot) bug.Snapshot {
27 comment := bug.Comment{
28 Message: op.Message,
29 Author: op.Author,
30 Time: op.Time,
31 }
32
33 snapshot.Comments = append(snapshot.Comments, comment)
34
35 return snapshot
36}