File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,15 +71,10 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
7171 snapshot .addActor (op .Author_ )
7272
7373 // Updating the corresponding comment
74-
75- //TODO use snapshot.SearchComment instead of iteration
76- //TODO put *editComment* in snapshot or add *edit* to Comment interface?
77- for i := range snapshot .Comments () {
78- if snapshot .Comments ()[i ].Id () == commentId {
79- snapshot .Comments ()[i ].Message = op .Message
80- snapshot .Comments ()[i ].Files = op .Files
81- break
82- }
74+ editedComment , err := snapshot .SearchComment (commentId )
75+ if err == nil {
76+ editedComment .Message = op .Message
77+ editedComment .Files = op .Files
8378 }
8479}
8580
Original file line number Diff line number Diff line change @@ -102,9 +102,11 @@ func (snap *Snapshot) SearchTimelineItem(id entity.Id) (TimelineItem, error) {
102102
103103// SearchComment will search for a comment matching the given hash
104104func (snap * Snapshot ) SearchComment (id entity.Id ) (* Comment , error ) {
105- for _ , c := range snap .comments {
105+ for i , c := range snap .comments {
106106 if c .id == id {
107- return & c , nil
107+ // NOTE don't return c or &c! Otherwise callers cannot change the
108+ // returned comment. As c is a copy the found comment!
109+ return & snap .comments [i ], nil
108110 }
109111 }
110112
You can’t perform that action at this time.
0 commit comments