diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-03-30 18:38:21 -0600 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2017-04-05 17:44:14 +0100 |
commit | 2058e71e63c9ac471137f831b4d04b6626968532 (patch) | |
tree | 5c06529ab83a209f8ad7b203d1f131a97041b0bf /app/models/diff_discussion.rb | |
parent | 874413cf701870a0fc1051f7c0a5fc4b4f884657 (diff) | |
download | gitlab-ce-2058e71e63c9ac471137f831b4d04b6626968532.tar.gz |
Extract commonalities between DiffDiscussion and LegacyDiffDiscussion
Diffstat (limited to 'app/models/diff_discussion.rb')
-rw-r--r-- | app/models/diff_discussion.rb | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/app/models/diff_discussion.rb b/app/models/diff_discussion.rb index 9c80b190b74..e349f743fdd 100644 --- a/app/models/diff_discussion.rb +++ b/app/models/diff_discussion.rb @@ -1,71 +1,27 @@ class DiffDiscussion < Discussion - NUMBER_OF_TRUNCATED_DIFF_LINES = 16 + include DiscussionOnDiff - delegate :line_code, - :original_line_code, - :diff_file, - :diff_line, - :for_line?, - :active?, + delegate :position, + :original_position, to: :first_note - delegate :file_path, - :blob, - :highlighted_diff_lines, - :diff_lines, - - to: :diff_file, - allow_nil: true - def self.build_discussion_id(note) - [*super(note), *unique_position_identifier(note)] + [*super(note), *note.position.key] 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 + super.merge( + original_position: original_position.to_json, + position: position.to_json, + ) end end |