diff options
| author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-03-14 20:08:02 +0100 |
|---|---|---|
| committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-03-14 20:08:02 +0100 |
| commit | 88f8d3a4d6521d1001bcea83c2fb7b7c4fe15f37 (patch) | |
| tree | 6396220c786e65563c8d0eb4dc1a88a60d3636c8 /app/models/note.rb | |
| parent | 76eeb316df2f256d0d3c41d97421f709a21a02a8 (diff) | |
| parent | b782e7c9732275175d79b485fcddc85e575d48dd (diff) | |
| download | gitlab-ce-88f8d3a4d6521d1001bcea83c2fb7b7c4fe15f37.tar.gz | |
Merge branch 'master' into 4009-external-users
Diffstat (limited to 'app/models/note.rb')
| -rw-r--r-- | app/models/note.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index 2e084b5c80c..b0c33f2eec5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -173,26 +173,29 @@ class Note < ActiveRecord::Base Note.where(noteable_id: noteable_id, noteable_type: noteable_type, line_code: line_code).last.try(:diff) end - # Check if such line of code exists in merge request diff - # If exists - its active discussion - # If not - its outdated diff + # Check if this note is part of an "active" discussion + # + # This will always return true for anything except MergeRequest noteables, + # which have special logic. + # + # If the note's current diff cannot be matched in the MergeRequest's current + # diff, it's considered inactive. def active? return true unless self.diff return false unless noteable return @active if defined?(@active) - diffs = noteable.diffs(Commit.max_diff_options) - notable_diff = diffs.find { |d| d.new_path == self.diff.new_path } + noteable_diff = find_noteable_diff - return @active = false if notable_diff.nil? + if noteable_diff + parsed_lines = Gitlab::Diff::Parser.new.parse(noteable_diff.diff.each_line) - parsed_lines = Gitlab::Diff::Parser.new.parse(notable_diff.diff.each_line) - # We cannot use ||= because @active may be false - @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line } - end + @active = parsed_lines.any? { |line_obj| line_obj.text == diff_line } + else + @active = false + end - def outdated? - !active? + @active end def diff_file_index @@ -380,6 +383,12 @@ class Note < ActiveRecord::Base self.line_code = nil if self.line_code.blank? end + # Find the diff on noteable that matches our own + def find_noteable_diff + diffs = noteable.diffs(Commit.max_diff_options) + diffs.find { |d| d.new_path == self.diff.new_path } + end + def awards_supported? (for_issue? || for_merge_request?) && !for_diff_line? end |
