@@ -34,12 +34,12 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
3434 // Todo: currently any message can be edited, even by a different author
3535 // crypto signature are needed.
3636
37- snapshot .addActor (op .Author_ )
37+ // Recreate the Comment Id to match on
38+ commentId := entity .CombineIds (snapshot .Id (), op .Target )
3839
3940 var target TimelineItem
40-
4141 for i , item := range snapshot .Timeline {
42- if item .Id () == op . Target {
42+ if item .Id () == commentId {
4343 target = snapshot .Timeline [i ]
4444 break
4545 }
@@ -51,7 +51,7 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
5151 }
5252
5353 comment := Comment {
54- id : op . Target ,
54+ id : commentId ,
5555 Message : op .Message ,
5656 Files : op .Files ,
5757 UnixTime : timestamp .Timestamp (op .UnixTime ),
@@ -62,12 +62,18 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
6262 target .Append (comment )
6363 case * AddCommentTimelineItem :
6464 target .Append (comment )
65+ default :
66+ // somehow, the target matched on something that is not a comment
67+ // we make the op a no-op
68+ return
6569 }
6670
71+ snapshot .addActor (op .Author_ )
72+
6773 // Updating the corresponding comment
6874
6975 for i := range snapshot .Comments {
70- if snapshot .Comments [i ].Id () == op . Target {
76+ if snapshot .Comments [i ].Id () == commentId {
7177 snapshot .Comments [i ].Message = op .Message
7278 snapshot .Comments [i ].Files = op .Files
7379 break
@@ -95,7 +101,7 @@ func (op *EditCommentOperation) Validate() error {
95101 return nil
96102}
97103
98- // UnmarshalJSON is a two step JSON unmarshalling
104+ // UnmarshalJSON is two steps JSON unmarshalling
99105// This workaround is necessary to avoid the inner OpBase.MarshalJSON
100106// overriding the outer op's MarshalJSON
101107func (op * EditCommentOperation ) UnmarshalJSON (data []byte ) error {
@@ -138,7 +144,7 @@ func NewEditCommentOp(author identity.Interface, unixTime int64, target entity.I
138144 }
139145}
140146
141- // Convenience function to apply the operation
147+ // EditComment is a convenience function to apply the operation
142148func EditComment (b Interface , author identity.Interface , unixTime int64 , target entity.Id , message string ) (* EditCommentOperation , error ) {
143149 return EditCommentWithFiles (b , author , unixTime , target , message , nil )
144150}
@@ -152,13 +158,13 @@ func EditCommentWithFiles(b Interface, author identity.Interface, unixTime int64
152158 return editCommentOp , nil
153159}
154160
155- // Convenience function to edit the body of a bug (the first comment)
161+ // EditCreateComment is a convenience function to edit the body of a bug (the first comment)
156162func EditCreateComment (b Interface , author identity.Interface , unixTime int64 , message string ) (* EditCommentOperation , error ) {
157163 createOp := b .FirstOp ().(* CreateOperation )
158164 return EditComment (b , author , unixTime , createOp .Id (), message )
159165}
160166
161- // Convenience function to edit the body of a bug (the first comment)
167+ // EditCreateCommentWithFiles is a convenience function to edit the body of a bug (the first comment)
162168func EditCreateCommentWithFiles (b Interface , author identity.Interface , unixTime int64 , message string , files []repository.Hash ) (* EditCommentOperation , error ) {
163169 createOp := b .FirstOp ().(* CreateOperation )
164170 return EditCommentWithFiles (b , author , unixTime , createOp .Id (), message , files )
0 commit comments