@ -18,11 +18,11 @@ import (
type CodeComments map [ string ] map [ int64 ] [ ] * Comment
type CodeComments map [ string ] map [ int64 ] [ ] * Comment
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
func FetchCodeComments ( ctx context . Context , issue * Issue , currentUser * user_model . User ) ( CodeComments , error ) {
func FetchCodeComments ( ctx context . Context , issue * Issue , currentUser * user_model . User , showOutdatedComments bool ) ( CodeComments , error ) {
return fetchCodeCommentsByReview ( ctx , issue , currentUser , nil )
return fetchCodeCommentsByReview ( ctx , issue , currentUser , nil , showOutdatedComments )
}
}
func fetchCodeCommentsByReview ( ctx context . Context , issue * Issue , currentUser * user_model . User , review * Review ) ( CodeComments , error ) {
func fetchCodeCommentsByReview ( ctx context . Context , issue * Issue , currentUser * user_model . User , review * Review , showOutdatedComments bool ) ( CodeComments , error ) {
pathToLineToComment := make ( CodeComments )
pathToLineToComment := make ( CodeComments )
if review == nil {
if review == nil {
review = & Review { ID : 0 }
review = & Review { ID : 0 }
@ -33,7 +33,7 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
ReviewID : review . ID ,
ReviewID : review . ID ,
}
}
comments , err := findCodeComments ( ctx , opts , issue , currentUser , review )
comments , err := findCodeComments ( ctx , opts , issue , currentUser , review , showOutdatedComments )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -47,15 +47,17 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
return pathToLineToComment , nil
return pathToLineToComment , nil
}
}
func findCodeComments ( ctx context . Context , opts FindCommentsOptions , issue * Issue , currentUser * user_model . User , review * Review ) ( [ ] * Comment , error ) {
func findCodeComments ( ctx context . Context , opts FindCommentsOptions , issue * Issue , currentUser * user_model . User , review * Review , showOutdatedComments bool ) ( [ ] * Comment , error ) {
var comments CommentList
var comments CommentList
if review == nil {
if review == nil {
review = & Review { ID : 0 }
review = & Review { ID : 0 }
}
}
conds := opts . ToConds ( )
conds := opts . ToConds ( )
if review . ID == 0 {
if ! showOutdatedComments && review . ID == 0 {
conds = conds . And ( builder . Eq { "invalidated" : false } )
conds = conds . And ( builder . Eq { "invalidated" : false } )
}
}
e := db . GetEngine ( ctx )
e := db . GetEngine ( ctx )
if err := e . Where ( conds ) .
if err := e . Where ( conds ) .
Asc ( "comment.created_unix" ) .
Asc ( "comment.created_unix" ) .
@ -118,12 +120,12 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
}
}
// FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
// FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
func FetchCodeCommentsByLine ( ctx context . Context , issue * Issue , currentUser * user_model . User , treePath string , line int64 ) ( [ ] * Comment , error ) {
func FetchCodeCommentsByLine ( ctx context . Context , issue * Issue , currentUser * user_model . User , treePath string , line int64 , showOutdatedComments bool ) ( [ ] * Comment , error ) {
opts := FindCommentsOptions {
opts := FindCommentsOptions {
Type : CommentTypeCode ,
Type : CommentTypeCode ,
IssueID : issue . ID ,
IssueID : issue . ID ,
TreePath : treePath ,
TreePath : treePath ,
Line : line ,
Line : line ,
}
}
return findCodeComments ( ctx , opts , issue , currentUser , nil )
return findCodeComments ( ctx , opts , issue , currentUser , nil , showOutdatedComments )
}
}