summaryrefslogtreecommitdiff
path: root/app/models/diff_discussion.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-03-09 19:29:11 -0600
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-05 17:44:14 +0100
commit08bbb9fce66cb46d3262e6cd4c4379b59f065be0 (patch)
tree159eeb7ca43419f29926d6e77637db18bddd20a9 /app/models/diff_discussion.rb
parent8bdfee8ba5fb0a8f48501e63274c8f9ce5708007 (diff)
downloadgitlab-ce-08bbb9fce66cb46d3262e6cd4c4379b59f065be0.tar.gz
Add option to start a new discussion on an MR
Diffstat (limited to 'app/models/diff_discussion.rb')
-rw-r--r--app/models/diff_discussion.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/app/models/diff_discussion.rb b/app/models/diff_discussion.rb
new file mode 100644
index 00000000000..9a934c7520c
--- /dev/null
+++ b/app/models/diff_discussion.rb
@@ -0,0 +1,69 @@
+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 self.build_discussion_id(note)
+ [*super(note), *unique_position_identifier(note)]
+ end
+
+ def self.build_original_discussion_id(note)
+ [*Discussion.build_discussion_id(note), *note.original_position.key]
+ end
+
+ def self.unique_position_identifier(note)
+ note.position.key
+ end
+
+ def diff_discussion?
+ true
+ end
+
+ def legacy_diff_discussion?
+ false
+ 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