diff_discussion.rb 1018 Bytes
Newer Older
1 2
# frozen_string_literal: true

Douwe Maan's avatar
Douwe Maan committed
3
# A discussion on merge request or commit diffs consisting of `DiffNote` notes.
4 5
#
# A discussion of this type can be resolvable.
6
class DiffDiscussion < Discussion
7
  include DiscussionOnDiff
8

9 10 11 12
  def self.note_class
    DiffNote
  end

13 14
  delegate  :position,
            :original_position,
15
            :change_position,
Felipe Artur's avatar
Felipe Artur committed
16 17
            :on_text?,
            :on_image?,
18 19 20 21 22 23 24

            to: :first_note

  def legacy_diff_discussion?
    false
  end

25 26 27
  def merge_request_version_params
    return unless for_merge_request?

28 29 30 31 32
    version_params = get_params

    return version_params unless on_merge_request_commit? && commit_id

    version_params ||= {}
33
    version_params.tap do |params|
34
      params[:commit_id] = commit_id
35
    end
36 37
  end

38
  def reply_attributes
39 40
    super.merge(
      original_position: original_position.to_json,
41
      position: position.to_json
42
    )
43
  end
44 45 46

  private

47
  def get_params
48 49 50
    return {} if active?

    noteable.version_params_for(position.diff_refs)
51
  end
52
end