2017-04-04 18:27:23 -04:00
|
|
|
# Contains functionality shared between `DiffDiscussion` and `LegacyDiffDiscussion`.
|
2017-03-30 20:38:21 -04:00
|
|
|
module DiscussionOnDiff
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2017-04-12 13:59:35 -04:00
|
|
|
NUMBER_OF_TRUNCATED_DIFF_LINES = 16
|
2017-03-30 20:38:21 -04:00
|
|
|
|
2017-04-12 13:59:35 -04:00
|
|
|
included do
|
2017-03-30 20:38:21 -04:00
|
|
|
delegate :line_code,
|
|
|
|
:original_line_code,
|
|
|
|
:diff_file,
|
|
|
|
:diff_line,
|
|
|
|
:for_line?,
|
|
|
|
:active?,
|
2017-04-30 16:32:09 -04:00
|
|
|
:created_at_diff?,
|
2017-03-30 20:38:21 -04:00
|
|
|
|
|
|
|
to: :first_note
|
|
|
|
|
|
|
|
delegate :file_path,
|
|
|
|
:blob,
|
|
|
|
:highlighted_diff_lines,
|
|
|
|
:diff_lines,
|
|
|
|
|
|
|
|
to: :diff_file,
|
|
|
|
allow_nil: true
|
|
|
|
end
|
|
|
|
|
|
|
|
def diff_discussion?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2017-10-07 00:25:17 -04:00
|
|
|
def file_new_path
|
|
|
|
first_note.position.new_path
|
|
|
|
end
|
|
|
|
|
2017-03-30 20:38:21 -04:00
|
|
|
# Returns an array of at most 16 highlighted lines above a diff note
|
|
|
|
def truncated_diff_lines(highlight: true)
|
|
|
|
lines = highlight ? highlighted_diff_lines : diff_lines
|
|
|
|
prev_lines = []
|
|
|
|
|
|
|
|
lines.each do |line|
|
|
|
|
if line.meta?
|
|
|
|
prev_lines.clear
|
|
|
|
else
|
|
|
|
prev_lines << line
|
|
|
|
|
|
|
|
break if for_line?(line)
|
|
|
|
|
|
|
|
prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
prev_lines
|
|
|
|
end
|
2017-05-24 11:10:10 -04:00
|
|
|
|
|
|
|
def line_code_in_diffs(diff_refs)
|
|
|
|
if active?(diff_refs)
|
|
|
|
line_code
|
|
|
|
elsif diff_refs && created_at_diff?(diff_refs)
|
|
|
|
original_line_code
|
|
|
|
end
|
|
|
|
end
|
2017-03-30 20:38:21 -04:00
|
|
|
end
|