summaryrefslogtreecommitdiff
path: root/app/services/discussions
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-05-31 14:31:33 -0500
committerDouwe Maan <douwe@selenight.nl>2017-05-31 14:34:56 -0500
commit09838ac626df739f0ab9852e3c7d862c7fd707e5 (patch)
tree833992848bc23c93f725f7ef2eb11518f14d3411 /app/services/discussions
parent8039b9c3c6caedc19e0e44d086a007e8975134b7 (diff)
downloadgitlab-ce-09838ac626df739f0ab9852e3c7d862c7fd707e5.tar.gz
Update diff discussion position per discussion instead of per notedm-update-discussion-diff-position
Diffstat (limited to 'app/services/discussions')
-rw-r--r--app/services/discussions/update_diff_position_service.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/services/discussions/update_diff_position_service.rb b/app/services/discussions/update_diff_position_service.rb
new file mode 100644
index 00000000000..1ef8d9edbe1
--- /dev/null
+++ b/app/services/discussions/update_diff_position_service.rb
@@ -0,0 +1,41 @@
+module Discussions
+ class UpdateDiffPositionService < BaseService
+ def execute(discussion)
+ result = tracer.trace(discussion.position)
+ return unless result
+
+ position = result[:position]
+ outdated = result[:outdated]
+
+ discussion.notes.each do |note|
+ if outdated
+ note.change_position = position
+ else
+ note.position = position
+ note.change_position = nil
+ end
+ end
+
+ Note.transaction do
+ discussion.notes.each do |note|
+ Gitlab::Timeless.timeless(note, &:save)
+ end
+
+ if outdated && current_user
+ SystemNoteService.diff_discussion_outdated(discussion, project, current_user, position)
+ end
+ end
+ end
+
+ private
+
+ def tracer
+ @tracer ||= Gitlab::Diff::PositionTracer.new(
+ project: project,
+ old_diff_refs: params[:old_diff_refs],
+ new_diff_refs: params[:new_diff_refs],
+ paths: params[:paths]
+ )
+ end
+ end
+end