本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1KB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package ui
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/git"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/notification/base"
  10. )
  11. type (
  12. notificationService struct {
  13. base.NullNotifier
  14. issueQueue chan issueNotificationOpts
  15. }
  16. issueNotificationOpts struct {
  17. issue *models.Issue
  18. notificationAuthorID int64
  19. }
  20. )
  21. var (
  22. _ base.Notifier = &notificationService{}
  23. )
  24. // NewNotifier create a new notificationService notifier
  25. func NewNotifier() base.Notifier {
  26. return &notificationService{
  27. issueQueue: make(chan issueNotificationOpts, 100),
  28. }
  29. }
  30. func (ns *notificationService) Run() {
  31. for opts := range ns.issueQueue {
  32. if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
  33. log.Error("Was unable to create issue notification: %v", err)
  34. }
  35. }
  36. }
  37. func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  38. issue *models.Issue, comment *models.Comment) {
  39. ns.issueQueue <- issueNotificationOpts{
  40. issue,
  41. doer.ID,
  42. }
  43. }
  44. func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
  45. ns.issueQueue <- issueNotificationOpts{
  46. issue,
  47. issue.Poster.ID,
  48. }
  49. }
  50. func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
  51. ns.issueQueue <- issueNotificationOpts{
  52. issue,
  53. doer.ID,
  54. }
  55. }
  56. func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) {
  57. ns.issueQueue <- issueNotificationOpts{
  58. pr.Issue,
  59. doer.ID,
  60. }
  61. }
  62. func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
  63. ns.issueQueue <- issueNotificationOpts{
  64. pr.Issue,
  65. pr.Issue.PosterID,
  66. }
  67. }
  68. func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
  69. ns.issueQueue <- issueNotificationOpts{
  70. pr.Issue,
  71. r.Reviewer.ID,
  72. }
  73. }
上海开阖软件有限公司 沪ICP备12045867号-1