@@ -1079,67 +1079,18 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
1079
1079
if review == nil {
1080
1080
review = & Review {ID : 0 }
1081
1081
}
1082
- //Find comments
1083
1082
opts := FindCommentsOptions {
1084
1083
Type : CommentTypeCode ,
1085
1084
IssueID : issue .ID ,
1086
1085
ReviewID : review .ID ,
1087
1086
}
1088
- conds := opts .toConds ()
1089
- if review .ID == 0 {
1090
- conds = conds .And (builder.Eq {"invalidated" : false })
1091
- }
1092
-
1093
- var comments []* Comment
1094
- if err := e .Where (conds ).
1095
- Asc ("comment.created_unix" ).
1096
- Asc ("comment.id" ).
1097
- Find (& comments ); err != nil {
1098
- return nil , err
1099
- }
1100
1087
1101
- if err := issue .loadRepo (e ); err != nil {
1102
- return nil , err
1103
- }
1104
-
1105
- if err := CommentList (comments ).loadPosters (e ); err != nil {
1106
- return nil , err
1107
- }
1108
-
1109
- // Find all reviews by ReviewID
1110
- reviews := make (map [int64 ]* Review )
1111
- var ids = make ([]int64 , 0 , len (comments ))
1112
- for _ , comment := range comments {
1113
- if comment .ReviewID != 0 {
1114
- ids = append (ids , comment .ReviewID )
1115
- }
1116
- }
1117
- if err := e .In ("id" , ids ).Find (& reviews ); err != nil {
1088
+ comments , err := findCodeComments (e , opts , issue , currentUser , review )
1089
+ if err != nil {
1118
1090
return nil , err
1119
1091
}
1120
1092
1121
1093
for _ , comment := range comments {
1122
- if err := comment .LoadResolveDoer (); err != nil {
1123
- return nil , err
1124
- }
1125
-
1126
- if err := comment .LoadReactions (issue .Repo ); err != nil {
1127
- return nil , err
1128
- }
1129
-
1130
- if re , ok := reviews [comment .ReviewID ]; ok && re != nil {
1131
- // If the review is pending only the author can see the comments (except the review is set)
1132
- if review .ID == 0 {
1133
- if re .Type == ReviewTypePending &&
1134
- (currentUser == nil || currentUser .ID != re .ReviewerID ) {
1135
- continue
1136
- }
1137
- }
1138
- comment .Review = re
1139
- }
1140
-
1141
- comment .RenderedContent = string (markdown .Render ([]byte (comment .Content ), issue .Repo .Link (),
1142
- issue .Repo .ComposeMetas ()))
1143
1094
if pathToLineToComment [comment .TreePath ] == nil {
1144
1095
pathToLineToComment [comment .TreePath ] = make (map [int64 ][]* Comment )
1145
1096
}
@@ -1148,16 +1099,16 @@ func fetchCodeCommentsByReview(e Engine, issue *Issue, currentUser *User, review
1148
1099
return pathToLineToComment , nil
1149
1100
}
1150
1101
1151
- // FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
1152
- func FetchCodeCommentsByLine (issue * Issue , currentUser * User , treePath string , line int64 ) ([]* Comment , error ) {
1153
- opts := FindCommentsOptions {
1154
- Type : CommentTypeCode ,
1155
- IssueID : issue .ID ,
1156
- TreePath : treePath ,
1157
- Line : line ,
1158
- }
1102
+ func findCodeComments (e Engine , opts FindCommentsOptions , issue * Issue , currentUser * User , review * Review ) ([]* Comment , error ) {
1159
1103
var comments []* Comment
1160
- if err := x .Where (opts .toConds ()).
1104
+ if review == nil {
1105
+ review = & Review {ID : 0 }
1106
+ }
1107
+ conds := opts .toConds ()
1108
+ if review .ID == 0 {
1109
+ conds = conds .And (builder.Eq {"invalidated" : false })
1110
+ }
1111
+ if err := x .Where (conds ).
1161
1112
Asc ("comment.created_unix" ).
1162
1113
Asc ("comment.id" ).
1163
1114
Find (& comments ); err != nil {
@@ -1184,7 +1135,19 @@ func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, l
1184
1135
return nil , err
1185
1136
}
1186
1137
1138
+ n := 0
1187
1139
for _ , comment := range comments {
1140
+ if re , ok := reviews [comment .ReviewID ]; ok && re != nil {
1141
+ // If the review is pending only the author can see the comments (except if the review is set)
1142
+ if review .ID == 0 && re .Type == ReviewTypePending &&
1143
+ (currentUser == nil || currentUser .ID != re .ReviewerID ) {
1144
+ continue
1145
+ }
1146
+ comment .Review = re
1147
+ }
1148
+ comments [n ] = comment
1149
+ n ++
1150
+
1188
1151
if err := comment .LoadResolveDoer (); err != nil {
1189
1152
return nil , err
1190
1153
}
@@ -1193,19 +1156,21 @@ func FetchCodeCommentsByLine(issue *Issue, currentUser *User, treePath string, l
1193
1156
return nil , err
1194
1157
}
1195
1158
1196
- if re , ok := reviews [comment .ReviewID ]; ok && re != nil {
1197
- // If the review is pending only the author can see the comments (except the review is set)
1198
- if re .Type == ReviewTypePending &&
1199
- (currentUser == nil || currentUser .ID != re .ReviewerID ) {
1200
- continue
1201
- }
1202
- comment .Review = re
1203
- }
1204
-
1205
1159
comment .RenderedContent = string (markdown .Render ([]byte (comment .Content ), issue .Repo .Link (),
1206
1160
issue .Repo .ComposeMetas ()))
1207
1161
}
1208
- return comments , nil
1162
+ return comments [:n ], nil
1163
+ }
1164
+
1165
+ // FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
1166
+ func FetchCodeCommentsByLine (issue * Issue , currentUser * User , treePath string , line int64 ) ([]* Comment , error ) {
1167
+ opts := FindCommentsOptions {
1168
+ Type : CommentTypeCode ,
1169
+ IssueID : issue .ID ,
1170
+ TreePath : treePath ,
1171
+ Line : line ,
1172
+ }
1173
+ return findCodeComments (x , opts , issue , currentUser , nil )
1209
1174
}
1210
1175
1211
1176
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
0 commit comments