debian-mirror-gitlab/app/models/diff_discussion.rb

64 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
# A discussion on merge request or commit diffs consisting of `DiffNote` notes.
#
# A discussion of this type can be resolvable.
class DiffDiscussion < Discussion
include DiscussionOnDiff
def self.note_class
DiffNote
end
2023-07-09 08:55:56 +05:30
delegate :position,
:original_position,
:change_position,
:diff_note_positions,
:on_text?,
:on_image?,
to: :first_note
2017-08-17 22:00:37 +05:30
def legacy_diff_discussion?
false
end
def merge_request_version_params
return unless for_merge_request?
2018-03-17 18:26:18 +05:30
version_params = get_params
return version_params unless on_merge_request_commit? && commit_id
version_params ||= {}
version_params.tap do |params|
params[:commit_id] = commit_id
end
2017-08-17 22:00:37 +05:30
end
def reply_attributes
super.merge(
2023-01-13 00:05:48 +05:30
original_position: Gitlab::Json.dump(original_position),
position: Gitlab::Json.dump(position)
2017-08-17 22:00:37 +05:30
)
end
2018-03-17 18:26:18 +05:30
2021-09-30 23:02:18 +05:30
def cache_key
2023-01-13 00:05:48 +05:30
positions_json = diff_note_positions.map { |dnp| Gitlab::Json.dump(dnp.position) }
2021-10-27 15:23:28 +05:30
positions_sha = Digest::SHA1.hexdigest(positions_json.join(':')) if positions_json.any?
2021-09-30 23:02:18 +05:30
[
super,
2023-01-13 00:05:48 +05:30
Digest::SHA1.hexdigest(Gitlab::Json.dump(position)),
2021-10-27 15:23:28 +05:30
positions_sha
2021-09-30 23:02:18 +05:30
].join(':')
end
2018-03-17 18:26:18 +05:30
private
def get_params
return {} if active?
noteable.version_params_for(position.diff_refs)
end
2017-08-17 22:00:37 +05:30
end