diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-06-05 19:21:08 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-06-05 19:21:08 -0500 |
commit | f31f3e423d5bb39f9880f8defe130e3db6a02dd0 (patch) | |
tree | c3ac1be45a85c2bd7cd0cc8a78c043ad4a6ac7e7 | |
parent | e29778f023b4ae225c4ec237d37487e474b85a5c (diff) | |
download | gitlab-ce-new-discussion-from-any-comment.tar.gz |
Have Note#discussion take a context_noteablenew-discussion-from-any-comment
-rw-r--r-- | app/models/note.rb | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/app/models/note.rb b/app/models/note.rb index f9a5a7aee9e..bb732239890 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -119,11 +119,11 @@ class Note < ActiveRecord::Base Discussion.build_collection(fresh, context_noteable) end - def find_discussion(discussion_id) + def find_discussion(discussion_id, context_noteable = nil) notes = where(discussion_id: discussion_id).fresh.to_a return if notes.empty? - Discussion.build(notes) + Discussion.build(notes, context_noteable) end def grouped_diff_discussions(diff_refs = nil) @@ -271,20 +271,20 @@ class Note < ActiveRecord::Base # This method exists as an alternative to `#discussion` to use when the methods # we intend to call on the Discussion object don't require it to have all of its notes, # and just depend on the first note or the type of discussion. This saves us a DB query. - def to_discussion(noteable = nil) - Discussion.build([self], noteable) + def to_discussion(context_noteable = nil) + Discussion.build([self], context_noteable) end # Returns the entire discussion this note is part of. # Consider using `#to_discussion` if we do not need to render the discussion # and all its notes and if we don't care about the discussion's resolvability status. - def discussion - full_discussion = self.noteable.notes.find_discussion(self.discussion_id) if part_of_discussion? - full_discussion || to_discussion + def discussion(context_noteable = nil) + full_discussion = self.noteable.notes.find_discussion(self.discussion_id, context_noteable) if part_of_discussion?(context_noteable) + full_discussion || to_discussion(context_noteable) end - def part_of_discussion? - !to_discussion.individual_note? + def part_of_discussion?(context_noteable = nil) + !to_discussion(context_noteable).individual_note? end def in_reply_to?(other) |