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.

134 lines
3.7 KiB

  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/git"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/log"
  9. "code.gitea.io/gitea/modules/notification/base"
  10. )
  11. type (
  12. notificationService struct {
  13. issueQueue chan issueNotificationOpts
  14. }
  15. issueNotificationOpts struct {
  16. issue *models.Issue
  17. notificationAuthorID int64
  18. }
  19. )
  20. var (
  21. _ base.Notifier = &notificationService{}
  22. )
  23. // NewNotifier create a new notificationService notifier
  24. func NewNotifier() base.Notifier {
  25. return &notificationService{
  26. issueQueue: make(chan issueNotificationOpts, 100),
  27. }
  28. }
  29. func (ns *notificationService) Run() {
  30. for {
  31. select {
  32. case opts := <-ns.issueQueue:
  33. if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
  34. log.Error(4, "Was unable to create issue notification: %v", err)
  35. }
  36. }
  37. }
  38. }
  39. func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  40. issue *models.Issue, comment *models.Comment) {
  41. ns.issueQueue <- issueNotificationOpts{
  42. issue,
  43. doer.ID,
  44. }
  45. }
  46. func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
  47. ns.issueQueue <- issueNotificationOpts{
  48. issue,
  49. issue.Poster.ID,
  50. }
  51. }
  52. func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
  53. ns.issueQueue <- issueNotificationOpts{
  54. issue,
  55. doer.ID,
  56. }
  57. }
  58. func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) {
  59. ns.issueQueue <- issueNotificationOpts{
  60. pr.Issue,
  61. doer.ID,
  62. }
  63. }
  64. func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
  65. ns.issueQueue <- issueNotificationOpts{
  66. pr.Issue,
  67. pr.Issue.PosterID,
  68. }
  69. }
  70. func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
  71. ns.issueQueue <- issueNotificationOpts{
  72. pr.Issue,
  73. r.Reviewer.ID,
  74. }
  75. }
  76. func (ns *notificationService) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
  77. }
  78. func (ns *notificationService) NotifyDeleteComment(doer *models.User, c *models.Comment) {
  79. }
  80. func (ns *notificationService) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
  81. }
  82. func (ns *notificationService) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
  83. }
  84. func (ns *notificationService) NotifyNewRelease(rel *models.Release) {
  85. }
  86. func (ns *notificationService) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
  87. }
  88. func (ns *notificationService) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
  89. }
  90. func (ns *notificationService) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
  91. }
  92. func (ns *notificationService) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
  93. }
  94. func (ns *notificationService) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) {
  95. }
  96. func (ns *notificationService) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
  97. }
  98. func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
  99. }
  100. func (ns *notificationService) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
  101. addedLabels []*models.Label, removedLabels []*models.Label) {
  102. }
  103. func (ns *notificationService) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  104. }
  105. func (ns *notificationService) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
  106. }