summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-05-21 20:48:28 +0800
committerGitHub <noreply@github.com>2023-05-21 20:48:28 +0800
commit64f6a5d113da0d5d187752c9398d6e8d22d24b79 (patch)
treef72aea0c5c32d6ee4df1c973eaf67f1058f0f1a1
parentedd8ea0b0d07f7fee0f8cf506975c8f3bec690ca (diff)
downloadgitea-64f6a5d113da0d5d187752c9398d6e8d22d24b79.tar.gz
gitea-64f6a5d113da0d5d187752c9398d6e8d22d24b79.zip
Use `CommentList` instead of `[]*Comment` (#24828)
As title.
-rw-r--r--models/issues/comment.go2
-rw-r--r--models/issues/comment_code.go4
-rw-r--r--models/issues/issue.go4
-rw-r--r--routers/api/v1/repo/issue_comment.go16
4 files changed, 13 insertions, 13 deletions
diff --git a/models/issues/comment.go b/models/issues/comment.go
index c7e815c8b6..bf2bbfa414 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -1048,7 +1048,7 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond {
}
// FindComments returns all comments according options
-func FindComments(ctx context.Context, opts *FindCommentsOptions) ([]*Comment, error) {
+func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList, error) {
comments := make([]*Comment, 0, 10)
sess := db.GetEngine(ctx).Where(opts.ToConds())
if opts.RepoID > 0 {
diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go
index 8475da1a8c..304ac4569f 100644
--- a/models/issues/comment_code.go
+++ b/models/issues/comment_code.go
@@ -48,7 +48,7 @@ func fetchCodeCommentsByReview(ctx context.Context, issue *Issue, currentUser *u
}
func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issue, currentUser *user_model.User, review *Review) ([]*Comment, error) {
- var comments []*Comment
+ var comments CommentList
if review == nil {
review = &Review{ID: 0}
}
@@ -68,7 +68,7 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
return nil, err
}
- if err := CommentList(comments).LoadPosters(ctx); err != nil {
+ if err := comments.LoadPosters(ctx); err != nil {
return nil, err
}
diff --git a/models/issues/issue.go b/models/issues/issue.go
index bf41a7ec28..fc046d273c 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -124,7 +124,7 @@ type Issue struct {
ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`
Attachments []*repo_model.Attachment `xorm:"-"`
- Comments []*Comment `xorm:"-"`
+ Comments CommentList `xorm:"-"`
Reactions ReactionList `xorm:"-"`
TotalTrackedTime int64 `xorm:"-"`
Assignees []*user_model.User `xorm:"-"`
@@ -353,7 +353,7 @@ func (issue *Issue) LoadAttributes(ctx context.Context) (err error) {
return err
}
- if err = CommentList(issue.Comments).loadAttributes(ctx); err != nil {
+ if err = issue.Comments.loadAttributes(ctx); err != nil {
return err
}
if issue.IsTimetrackerEnabled(ctx) {
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index 7c8f30f116..5616e255ad 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -90,12 +90,12 @@ func ListIssueComments(ctx *context.APIContext) {
return
}
- if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
+ if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
- if err := issues_model.CommentList(comments).LoadAttachments(ctx); err != nil {
+ if err := comments.LoadAttachments(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
return
}
@@ -182,7 +182,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) {
return
}
- if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
+ if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
@@ -285,25 +285,25 @@ func ListRepoIssueComments(ctx *context.APIContext) {
return
}
- if err = issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
+ if err = comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
apiComments := make([]*api.Comment, len(comments))
- if err := issues_model.CommentList(comments).LoadIssues(ctx); err != nil {
+ if err := comments.LoadIssues(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadIssues", err)
return
}
- if err := issues_model.CommentList(comments).LoadPosters(ctx); err != nil {
+ if err := comments.LoadPosters(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadPosters", err)
return
}
- if err := issues_model.CommentList(comments).LoadAttachments(ctx); err != nil {
+ if err := comments.LoadAttachments(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadAttachments", err)
return
}
- if _, err := issues_model.CommentList(comments).Issues().LoadRepositories(ctx); err != nil {
+ if _, err := comments.Issues().LoadRepositories(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "LoadRepositories", err)
return
}