Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions bug/op_edit_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
// Todo: currently any message can be edited, even by a different author
// crypto signature are needed.

// Recreate the Comment Id to match on
commentId := entity.CombineIds(snapshot.Id(), op.Target)
comment := Comment{
id: op.Target,
Message: op.Message,
Files: op.Files,
UnixTime: timestamp.Timestamp(op.UnixTime),
}

var target TimelineItem
for i, item := range snapshot.Timeline {
if item.Id() == commentId {
if item.Id() == comment.id {
target = snapshot.Timeline[i]
break
}
Expand All @@ -50,13 +54,6 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
return
}

comment := Comment{
id: commentId,
Message: op.Message,
Files: op.Files,
UnixTime: timestamp.Timestamp(op.UnixTime),
}

switch target := target.(type) {
case *CreateTimelineItem:
target.Append(comment)
Expand All @@ -73,7 +70,7 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) {
// Updating the corresponding comment

for i := range snapshot.Comments {
if snapshot.Comments[i].Id() == commentId {
if snapshot.Comments[i].Id() == comment.id {
snapshot.Comments[i].Message = op.Message
snapshot.Comments[i].Files = op.Files
break
Expand Down