@@ -18,11 +18,11 @@ import (
1818type CodeComments map [string ]map [int64 ][]* Comment
1919
2020// FetchCodeComments will return a 2d-map: ["Path"]["Line"] = Comments at line
21- func FetchCodeComments (ctx context.Context , issue * Issue , currentUser * user_model.User ) (CodeComments , error ) {
22- return fetchCodeCommentsByReview (ctx , issue , currentUser , nil )
21+ func FetchCodeComments (ctx context.Context , issue * Issue , currentUser * user_model.User , showOutdatedComments bool ) (CodeComments , error ) {
22+ return fetchCodeCommentsByReview (ctx , issue , currentUser , nil , showOutdatedComments )
2323}
2424
25- func fetchCodeCommentsByReview (ctx context.Context , issue * Issue , currentUser * user_model.User , review * Review ) (CodeComments , error ) {
25+ func fetchCodeCommentsByReview (ctx context.Context , issue * Issue , currentUser * user_model.User , review * Review , showOutdatedComments bool ) (CodeComments , error ) {
2626 pathToLineToComment := make (CodeComments )
2727 if review == nil {
2828 review = & Review {ID : 0 }
@@ -33,7 +33,7 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
3333 ReviewID : review .ID ,
3434 }
3535
36- comments , err := findCodeComments (ctx , opts , issue , currentUser , review )
36+ comments , err := findCodeComments (ctx , opts , issue , currentUser , review , showOutdatedComments )
3737 if err != nil {
3838 return nil , err
3939 }
@@ -47,15 +47,17 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
4747 return pathToLineToComment , nil
4848}
4949
50- func findCodeComments (ctx context.Context , opts FindCommentsOptions , issue * Issue , currentUser * user_model.User , review * Review ) ([]* Comment , error ) {
50+ func findCodeComments (ctx context.Context , opts FindCommentsOptions , issue * Issue , currentUser * user_model.User , review * Review , showOutdatedComments bool ) ([]* Comment , error ) {
5151 var comments CommentList
5252 if review == nil {
5353 review = & Review {ID : 0 }
5454 }
5555 conds := opts .ToConds ()
56- if review .ID == 0 {
56+
57+ if ! showOutdatedComments && review .ID == 0 {
5758 conds = conds .And (builder.Eq {"invalidated" : false })
5859 }
60+
5961 e := db .GetEngine (ctx )
6062 if err := e .Where (conds ).
6163 Asc ("comment.created_unix" ).
@@ -118,12 +120,12 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
118120}
119121
120122// FetchCodeCommentsByLine fetches the code comments for a given treePath and line number
121- func FetchCodeCommentsByLine (ctx context.Context , issue * Issue , currentUser * user_model.User , treePath string , line int64 ) ([]* Comment , error ) {
123+ func FetchCodeCommentsByLine (ctx context.Context , issue * Issue , currentUser * user_model.User , treePath string , line int64 , showOutdatedComments bool ) ([]* Comment , error ) {
122124 opts := FindCommentsOptions {
123125 Type : CommentTypeCode ,
124126 IssueID : issue .ID ,
125127 TreePath : treePath ,
126128 Line : line ,
127129 }
128- return findCodeComments (ctx , opts , issue , currentUser , nil )
130+ return findCodeComments (ctx , opts , issue , currentUser , nil , showOutdatedComments )
129131}
0 commit comments