diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-11-27 22:12:02 +0800 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-11-30 17:46:46 +0800 |
commit | 842486f5c812a5a1c7eb585a14f7acbee92ad3a6 (patch) | |
tree | 5c64aca547dd08308c9bb755636c16cce60803c1 /app/models/diff_discussion.rb | |
parent | 098066050d148deb024fdec6c36bfe9320c674bd (diff) | |
download | gitlab-ce-new-resolvable-discussion.tar.gz |
Diffstat (limited to 'app/models/diff_discussion.rb')
-rw-r--r-- | app/models/diff_discussion.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/app/models/diff_discussion.rb b/app/models/diff_discussion.rb new file mode 100644 index 00000000000..1b24b5d1faa --- /dev/null +++ b/app/models/diff_discussion.rb @@ -0,0 +1,61 @@ +class DiffDiscussion < Discussion + NUMBER_OF_TRUNCATED_DIFF_LINES = 16 + + delegate :line_code, + :original_line_code, + :diff_file, + :for_line?, + :active?, + + to: :first_note + + delegate :blob, + :highlighted_diff_lines, + :diff_lines, + + to: :diff_file, + allow_nil: true + + def diff_discussion? + true + end + + def legacy_diff_discussion? + false + end + + def potentially_resolvable? + first_note.for_merge_request? + end + + def active? + return @active if @active.present? + + @active = first_note.active? + end + MEMOIZED_VALUES << :active + + def reply_attributes + super.merge(first_note.diff_attributes) + end + + # 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 +end |