@@ -73,7 +73,7 @@ def note
73
73
end
74
74
alias_method :awardable , :note
75
75
76
- def note_to_html ( note )
76
+ def note_html ( note )
77
77
render_to_string (
78
78
"projects/notes/_note" ,
79
79
layout : false ,
@@ -82,20 +82,20 @@ def note_to_html(note)
82
82
)
83
83
end
84
84
85
- def note_to_discussion_html ( note )
86
- return unless note . diff_note ?
85
+ def diff_discussion_html ( discussion )
86
+ return unless discussion . diff_discussion ?
87
87
88
88
if params [ :view ] == 'parallel'
89
- template = "projects/notes/_diff_notes_with_reply_parallel "
89
+ template = "discussions/_parallel_diff_discussion "
90
90
locals =
91
91
if params [ :line_type ] == 'old'
92
- { notes_left : [ note ] , notes_right : [ ] }
92
+ { discussion_left : discussion , discussion_right : nil }
93
93
else
94
- { notes_left : [ ] , notes_right : [ note ] }
94
+ { discussion_left : nil , discussion_right : discussion }
95
95
end
96
96
else
97
- template = "projects/notes/_diff_notes_with_reply "
98
- locals = { notes : [ note ] }
97
+ template = "discussions/_diff_discussion "
98
+ locals = { discussion : discussion }
99
99
end
100
100
101
101
render_to_string (
@@ -106,14 +106,14 @@ def note_to_discussion_html(note)
106
106
)
107
107
end
108
108
109
- def note_to_discussion_with_diff_html ( note )
110
- return unless note . diff_note ?
109
+ def discussion_html ( discussion )
110
+ return unless discussion . diff_discussion ?
111
111
112
112
render_to_string (
113
- "projects/notes /_discussion" ,
113
+ "discussions /_discussion" ,
114
114
layout : false ,
115
115
formats : [ :html ] ,
116
- locals : { discussion_notes : [ note ] }
116
+ locals : { discussion : discussion }
117
117
)
118
118
end
119
119
@@ -132,26 +132,33 @@ def note_json(note)
132
132
valid : true ,
133
133
id : note . id ,
134
134
discussion_id : note . discussion_id ,
135
- html : note_to_html ( note ) ,
135
+ html : note_html ( note ) ,
136
136
award : false ,
137
- note : note . note ,
138
- discussion_html : note_to_discussion_html ( note ) ,
139
- discussion_with_diff_html : note_to_discussion_with_diff_html ( note )
137
+ note : note . note
140
138
}
141
139
142
- # The discussion_id is used to add the comment to the correct discussion
143
- # element on the merge request page. Among other things, the discussion_id
144
- # contains the sha of head commit of the merge request.
145
- # When new commits are pushed into the merge request after the initial
146
- # load of the merge request page, the discussion elements will still have
147
- # the old discussion_ids, with the old head commit sha. The new comment,
148
- # however, will have the new discussion_id with the new commit sha.
149
- # To ensure that these new comments will still end up in the correct
150
- # discussion element, we also send the original discussion_id, with the
151
- # old commit sha, along, and fall back on this value when no discussion
152
- # element with the new discussion_id could be found.
153
- if note . new_diff_note? && note . position != note . original_position
154
- attrs [ :original_discussion_id ] = note . original_discussion_id
140
+ if note . diff_note?
141
+ discussion = Discussion . new ( [ note ] )
142
+
143
+ attrs . merge! (
144
+ diff_discussion_html : diff_discussion_html ( discussion ) ,
145
+ discussion_html : discussion_html ( discussion )
146
+ )
147
+
148
+ # The discussion_id is used to add the comment to the correct discussion
149
+ # element on the merge request page. Among other things, the discussion_id
150
+ # contains the sha of head commit of the merge request.
151
+ # When new commits are pushed into the merge request after the initial
152
+ # load of the merge request page, the discussion elements will still have
153
+ # the old discussion_ids, with the old head commit sha. The new comment,
154
+ # however, will have the new discussion_id with the new commit sha.
155
+ # To ensure that these new comments will still end up in the correct
156
+ # discussion element, we also send the original discussion_id, with the
157
+ # old commit sha, along, and fall back on this value when no discussion
158
+ # element with the new discussion_id could be found.
159
+ if note . new_diff_note? && note . position != note . original_position
160
+ attrs [ :original_discussion_id ] = note . original_discussion_id
161
+ end
155
162
end
156
163
157
164
attrs
0 commit comments