gitea
Зеркало из https://github.com/go-gitea/gitea
1// Copyright 2024 The Gitea Authors. All rights reserved.
2// SPDX-License-Identifier: MIT
3
4package issue
5
6import (
7"context"
8
9issues_model "code.gitea.io/gitea/models/issues"
10user_model "code.gitea.io/gitea/models/user"
11)
12
13// CreateIssueReaction creates a reaction on an issue.
14func CreateIssueReaction(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, content string) (*issues_model.Reaction, error) {
15if err := issue.LoadRepo(ctx); err != nil {
16return nil, err
17}
18
19if user_model.IsUserBlockedBy(ctx, doer, issue.PosterID, issue.Repo.OwnerID) {
20return nil, user_model.ErrBlockedUser
21}
22
23return issues_model.CreateReaction(ctx, &issues_model.ReactionOptions{
24Type: content,
25DoerID: doer.ID,
26IssueID: issue.ID,
27})
28}
29
30// CreateCommentReaction creates a reaction on a comment.
31func CreateCommentReaction(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, content string) (*issues_model.Reaction, error) {
32if err := comment.LoadIssue(ctx); err != nil {
33return nil, err
34}
35
36if err := comment.Issue.LoadRepo(ctx); err != nil {
37return nil, err
38}
39
40if user_model.IsUserBlockedBy(ctx, doer, comment.Issue.PosterID, comment.Issue.Repo.OwnerID, comment.PosterID) {
41return nil, user_model.ErrBlockedUser
42}
43
44return issues_model.CreateReaction(ctx, &issues_model.ReactionOptions{
45Type: content,
46DoerID: doer.ID,
47IssueID: comment.Issue.ID,
48CommentID: comment.ID,
49})
50}
51