gitea

Зеркало из https://github.com/go-gitea/gitea
Форк
0
/
reaction.go 
50 строк · 1.4 Кб
1
// Copyright 2024 The Gitea Authors. All rights reserved.
2
// SPDX-License-Identifier: MIT
3

4
package issue
5

6
import (
7
	"context"
8

9
	issues_model "code.gitea.io/gitea/models/issues"
10
	user_model "code.gitea.io/gitea/models/user"
11
)
12

13
// CreateIssueReaction creates a reaction on an issue.
14
func CreateIssueReaction(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, content string) (*issues_model.Reaction, error) {
15
	if err := issue.LoadRepo(ctx); err != nil {
16
		return nil, err
17
	}
18

19
	if user_model.IsUserBlockedBy(ctx, doer, issue.PosterID, issue.Repo.OwnerID) {
20
		return nil, user_model.ErrBlockedUser
21
	}
22

23
	return issues_model.CreateReaction(ctx, &issues_model.ReactionOptions{
24
		Type:    content,
25
		DoerID:  doer.ID,
26
		IssueID: issue.ID,
27
	})
28
}
29

30
// CreateCommentReaction creates a reaction on a comment.
31
func CreateCommentReaction(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, content string) (*issues_model.Reaction, error) {
32
	if err := comment.LoadIssue(ctx); err != nil {
33
		return nil, err
34
	}
35

36
	if err := comment.Issue.LoadRepo(ctx); err != nil {
37
		return nil, err
38
	}
39

40
	if user_model.IsUserBlockedBy(ctx, doer, comment.Issue.PosterID, comment.Issue.Repo.OwnerID, comment.PosterID) {
41
		return nil, user_model.ErrBlockedUser
42
	}
43

44
	return issues_model.CreateReaction(ctx, &issues_model.ReactionOptions{
45
		Type:      content,
46
		DoerID:    doer.ID,
47
		IssueID:   comment.Issue.ID,
48
		CommentID: comment.ID,
49
	})
50
}
51

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.