summaryrefslogtreecommitdiff
path: root/app/controllers/notes_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/notes_controller.rb')
-rw-r--r--app/controllers/notes_controller.rb41
1 files changed, 36 insertions, 5 deletions
diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb
index d794f368f57..000c7bbb641 100644
--- a/app/controllers/notes_controller.rb
+++ b/app/controllers/notes_controller.rb
@@ -6,10 +6,12 @@ class NotesController < ProjectResourceController
respond_to :js
def index
- notes
+ @notes = Notes::LoadContext.new(project, current_user, params).execute
+ @target_type = params[:target_type].camelize
+ @target_id = params[:target_id]
+
if params[:target_type] == "merge_request"
- @mixed_targets = true
- @main_target_type = params[:target_type].camelize
+ @discussions = discussions_from_notes
end
respond_with(@notes)
@@ -17,6 +19,8 @@ class NotesController < ProjectResourceController
def create
@note = Notes::CreateContext.new(project, current_user, params).execute
+ @target_type = params[:target_type].camelize
+ @target_id = params[:target_id]
respond_to do |format|
format.html {redirect_to :back}
@@ -40,7 +44,34 @@ class NotesController < ProjectResourceController
protected
- def notes
- @notes = Notes::LoadContext.new(project, current_user, params).execute
+ def discussion_notes_for(note)
+ @notes.select do |other_note|
+ note.discussion_id == other_note.discussion_id
+ end
+ end
+
+ def discussions_from_notes
+ discussion_ids = []
+ discussions = []
+
+ @notes.each do |note|
+ next if discussion_ids.include?(note.discussion_id)
+
+ # don't group notes for the main target
+ if note_for_main_target?(note)
+ discussions << [note]
+ else
+ discussions << discussion_notes_for(note)
+ discussion_ids << note.discussion_id
+ end
+ end
+
+ discussions
+ end
+
+ # Helps to distinguish e.g. commit notes in mr notes list
+ def note_for_main_target?(note)
+ note.for_wall? ||
+ (@target_type.camelize == note.noteable_type && !note.for_diff_line?)
end
end