From 3706144276e36833e6d6b1d6a84ee300cba4e5a1 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 16 Sep 2022 18:30:14 +0800 Subject: [PATCH 1/2] fix: use right FindReactionsOptions --- models/issues/reaction.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/issues/reaction.go b/models/issues/reaction.go index 87d6ff431054a..4e06f35518e6a 100644 --- a/models/issues/reaction.go +++ b/models/issues/reaction.go @@ -181,6 +181,10 @@ func createReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, erro Reaction: opts.Type, UserID: opts.DoerID, } + if findOpts.CommentID == 0 { + // explicit search of Issue Reactions where CommentID = 0 + findOpts.CommentID = -1 + } existingR, _, err := FindReactions(ctx, findOpts) if err != nil { From 9c13e5934c420870c52f0495e2e823593b782a51 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Fri, 16 Sep 2022 22:35:46 +0800 Subject: [PATCH 2/2] fix: delete reactioni with -1 comment id --- models/issues/reaction.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/models/issues/reaction.go b/models/issues/reaction.go index 4e06f35518e6a..e7295c8af8190 100644 --- a/models/issues/reaction.go +++ b/models/issues/reaction.go @@ -260,16 +260,23 @@ func DeleteReaction(ctx context.Context, opts *ReactionOptions) error { CommentID: opts.CommentID, } - _, err := db.GetEngine(ctx).Where("original_author_id = 0").Delete(reaction) + sess := db.GetEngine(ctx).Where("original_author_id = 0") + if opts.CommentID == -1 { + reaction.CommentID = 0 + sess.MustCols("comment_id") + } + + _, err := sess.Delete(reaction) return err } // DeleteIssueReaction deletes a reaction on issue. func DeleteIssueReaction(doerID, issueID int64, content string) error { return DeleteReaction(db.DefaultContext, &ReactionOptions{ - Type: content, - DoerID: doerID, - IssueID: issueID, + Type: content, + DoerID: doerID, + IssueID: issueID, + CommentID: -1, }) }