Skip to content

Commit 34f736c

Browse files
wolfogrelafriks
andauthored
Fix reaction of issues (#21185)
Fix #20860. `CommentID` in `FindReactionsOptions` should be -1 to search reactions with zero comment id. https://github.com/go-gitea/gitea/blob/8351172b6e5221290dc5b2c81e159e2eec0b43c8/models/issues/reaction.go#L108-L121 Co-authored-by: Lauris BH <[email protected]>
1 parent 43c10de commit 34f736c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: models/issues/reaction.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ func createReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, erro
181181
Reaction: opts.Type,
182182
UserID: opts.DoerID,
183183
}
184+
if findOpts.CommentID == 0 {
185+
// explicit search of Issue Reactions where CommentID = 0
186+
findOpts.CommentID = -1
187+
}
184188

185189
existingR, _, err := FindReactions(ctx, findOpts)
186190
if err != nil {
@@ -256,16 +260,23 @@ func DeleteReaction(ctx context.Context, opts *ReactionOptions) error {
256260
CommentID: opts.CommentID,
257261
}
258262

259-
_, err := db.GetEngine(ctx).Where("original_author_id = 0").Delete(reaction)
263+
sess := db.GetEngine(ctx).Where("original_author_id = 0")
264+
if opts.CommentID == -1 {
265+
reaction.CommentID = 0
266+
sess.MustCols("comment_id")
267+
}
268+
269+
_, err := sess.Delete(reaction)
260270
return err
261271
}
262272

263273
// DeleteIssueReaction deletes a reaction on issue.
264274
func DeleteIssueReaction(doerID, issueID int64, content string) error {
265275
return DeleteReaction(db.DefaultContext, &ReactionOptions{
266-
Type: content,
267-
DoerID: doerID,
268-
IssueID: issueID,
276+
Type: content,
277+
DoerID: doerID,
278+
IssueID: issueID,
279+
CommentID: -1,
269280
})
270281
}
271282

0 commit comments

Comments
 (0)