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

ui.go 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 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 {
  32. select {
  33. case opts := <-ns.issueQueue:
  34. if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
  35. log.Error(4, "Was unable to create issue notification: %v", err)
  36. }
  37. }
  38. }
  39. }
  40. func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  41. issue *models.Issue, comment *models.Comment) {
  42. ns.issueQueue <- issueNotificationOpts{
  43. issue,
  44. doer.ID,
  45. }
  46. }
  47. func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
  48. ns.issueQueue <- issueNotificationOpts{
  49. issue,
  50. issue.Poster.ID,
  51. }
  52. }
  53. func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
  54. ns.issueQueue <- issueNotificationOpts{
  55. issue,
  56. doer.ID,
  57. }
  58. }
  59. func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) {
  60. ns.issueQueue <- issueNotificationOpts{
  61. pr.Issue,
  62. doer.ID,
  63. }
  64. }
  65. func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
  66. ns.issueQueue <- issueNotificationOpts{
  67. pr.Issue,
  68. pr.Issue.PosterID,
  69. }
  70. }
  71. func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
  72. ns.issueQueue <- issueNotificationOpts{
  73. pr.Issue,
  74. r.Reviewer.ID,
  75. }
  76. }