2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-04 18:27:23 -04:00
|
|
|
# A discussion on merge request or commit diffs consisting of `DiffNote` notes.
|
2017-04-06 11:05:57 -04:00
|
|
|
#
|
|
|
|
# A discussion of this type can be resolvable.
|
2017-03-09 20:29:11 -05:00
|
|
|
class DiffDiscussion < Discussion
|
2017-03-30 20:38:21 -04:00
|
|
|
include DiscussionOnDiff
|
2017-03-09 20:29:11 -05:00
|
|
|
|
2017-04-06 11:05:57 -04:00
|
|
|
def self.note_class
|
|
|
|
DiffNote
|
|
|
|
end
|
|
|
|
|
2017-03-30 20:38:21 -04:00
|
|
|
delegate :position,
|
|
|
|
:original_position,
|
2017-05-31 15:31:33 -04:00
|
|
|
:change_position,
|
2020-04-15 14:09:36 -04:00
|
|
|
:diff_note_positions,
|
2017-10-07 00:25:17 -04:00
|
|
|
:on_text?,
|
|
|
|
:on_image?,
|
2017-03-09 20:29:11 -05:00
|
|
|
to: :first_note
|
|
|
|
|
|
|
|
def legacy_diff_discussion?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2017-04-30 16:32:09 -04:00
|
|
|
def merge_request_version_params
|
|
|
|
return unless for_merge_request?
|
|
|
|
|
2017-12-28 06:17:31 -05:00
|
|
|
version_params = get_params
|
|
|
|
|
|
|
|
return version_params unless on_merge_request_commit? && commit_id
|
|
|
|
|
|
|
|
version_params ||= {}
|
2017-12-18 12:02:45 -05:00
|
|
|
version_params.tap do |params|
|
2017-12-28 06:17:31 -05:00
|
|
|
params[:commit_id] = commit_id
|
2017-06-29 17:19:09 -04:00
|
|
|
end
|
2017-04-30 16:32:09 -04:00
|
|
|
end
|
|
|
|
|
2017-03-09 20:29:11 -05:00
|
|
|
def reply_attributes
|
2017-03-30 20:38:21 -04:00
|
|
|
super.merge(
|
|
|
|
original_position: original_position.to_json,
|
2017-05-03 07:27:17 -04:00
|
|
|
position: position.to_json
|
2017-03-30 20:38:21 -04:00
|
|
|
)
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|
2017-12-18 10:21:33 -05:00
|
|
|
|
2021-07-15 02:09:39 -04:00
|
|
|
def cache_key
|
2021-08-11 14:10:52 -04:00
|
|
|
positions_json = diff_note_positions.map { |dnp| dnp.position.to_json }
|
|
|
|
positions_sha = Digest::SHA1.hexdigest(positions_json.join(':')) if positions_json.any?
|
|
|
|
|
2021-07-15 02:09:39 -04:00
|
|
|
[
|
|
|
|
super,
|
2021-08-11 14:10:52 -04:00
|
|
|
Digest::SHA1.hexdigest(position.to_json),
|
|
|
|
positions_sha
|
2021-07-15 02:09:39 -04:00
|
|
|
].join(':')
|
|
|
|
end
|
|
|
|
|
2017-12-18 10:21:33 -05:00
|
|
|
private
|
|
|
|
|
2017-12-28 06:17:31 -05:00
|
|
|
def get_params
|
2017-12-18 12:02:45 -05:00
|
|
|
return {} if active?
|
|
|
|
|
|
|
|
noteable.version_params_for(position.diff_refs)
|
2017-12-18 10:21:33 -05:00
|
|
|
end
|
2017-03-09 20:29:11 -05:00
|
|
|
end
|