1
0
Fork 0
forked from forgejo/forgejo

Move reaction to models/issues/ (#19264)

* Move reaction to models/issues/

* Fix test

* move the function

* improve code

* Update models/issues/reaction.go

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Lunny Xiao 2022-03-31 17:20:39 +08:00 committed by GitHub
parent 43332a483f
commit d4f84f1c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 280 additions and 274 deletions

View file

@ -244,7 +244,7 @@ type Comment struct {
CommitSHA string `xorm:"VARCHAR(40)"`
Attachments []*repo_model.Attachment `xorm:"-"`
Reactions ReactionList `xorm:"-"`
Reactions issues.ReactionList `xorm:"-"`
// For view issue page.
ShowRole RoleDescriptor `xorm:"-"`
@ -631,11 +631,11 @@ func (c *Comment) LoadTime() error {
return err
}
func (c *Comment) loadReactions(e db.Engine, repo *repo_model.Repository) (err error) {
func (c *Comment) loadReactions(ctx context.Context, repo *repo_model.Repository) (err error) {
if c.Reactions != nil {
return nil
}
c.Reactions, _, err = findReactions(e, FindReactionsOptions{
c.Reactions, _, err = issues.FindReactions(ctx, issues.FindReactionsOptions{
IssueID: c.IssueID,
CommentID: c.ID,
})
@ -643,7 +643,7 @@ func (c *Comment) loadReactions(e db.Engine, repo *repo_model.Repository) (err e
return err
}
// Load reaction user data
if _, err := c.Reactions.loadUsers(e, repo); err != nil {
if _, err := c.Reactions.LoadUsers(ctx, repo); err != nil {
return err
}
return nil
@ -651,7 +651,7 @@ func (c *Comment) loadReactions(e db.Engine, repo *repo_model.Repository) (err e
// LoadReactions loads comment reactions
func (c *Comment) LoadReactions(repo *repo_model.Repository) error {
return c.loadReactions(db.GetEngine(db.DefaultContext), repo)
return c.loadReactions(db.DefaultContext, repo)
}
func (c *Comment) loadReview(e db.Engine) (err error) {
@ -1146,14 +1146,15 @@ func DeleteComment(comment *Comment) error {
}
defer committer.Close()
if err := deleteComment(db.GetEngine(ctx), comment); err != nil {
if err := deleteComment(ctx, comment); err != nil {
return err
}
return committer.Commit()
}
func deleteComment(e db.Engine, comment *Comment) error {
func deleteComment(ctx context.Context, comment *Comment) error {
e := db.GetEngine(ctx)
if _, err := e.ID(comment.ID).NoAutoCondition().Delete(comment); err != nil {
return err
}
@ -1177,7 +1178,7 @@ func deleteComment(e db.Engine, comment *Comment) error {
return err
}
return deleteReaction(e, &ReactionOptions{Comment: comment})
return issues.DeleteReaction(ctx, &issues.ReactionOptions{CommentID: comment.ID})
}
// CodeComments represents comments on code by using this structure: FILENAME -> LINE (+ == proposed; - == previous) -> COMMENTS