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.

ui.go 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. issueID int64
  18. commentID int64
  19. notificationAuthorID int64
  20. }
  21. )
  22. var (
  23. _ base.Notifier = &notificationService{}
  24. )
  25. // NewNotifier create a new notificationService notifier
  26. func NewNotifier() base.Notifier {
  27. return &notificationService{
  28. issueQueue: make(chan issueNotificationOpts, 100),
  29. }
  30. }
  31. func (ns *notificationService) Run() {
  32. for opts := range ns.issueQueue {
  33. if err := models.CreateOrUpdateIssueNotifications(opts.issueID, opts.commentID, opts.notificationAuthorID); err != nil {
  34. log.Error("Was unable to create issue notification: %v", err)
  35. }
  36. }
  37. }
  38. func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
  39. issue *models.Issue, comment *models.Comment) {
  40. var opts = issueNotificationOpts{
  41. issueID: issue.ID,
  42. notificationAuthorID: doer.ID,
  43. }
  44. if comment != nil {
  45. opts.commentID = comment.ID
  46. }
  47. ns.issueQueue <- opts
  48. }
  49. func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
  50. ns.issueQueue <- issueNotificationOpts{
  51. issueID: issue.ID,
  52. notificationAuthorID: issue.Poster.ID,
  53. }
  54. }
  55. func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
  56. ns.issueQueue <- issueNotificationOpts{
  57. issueID: issue.ID,
  58. notificationAuthorID: doer.ID,
  59. }
  60. }
  61. func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) {
  62. ns.issueQueue <- issueNotificationOpts{
  63. issueID: pr.Issue.ID,
  64. notificationAuthorID: doer.ID,
  65. }
  66. }
  67. func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
  68. ns.issueQueue <- issueNotificationOpts{
  69. issueID: pr.Issue.ID,
  70. notificationAuthorID: pr.Issue.PosterID,
  71. }
  72. }
  73. func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
  74. var opts = issueNotificationOpts{
  75. issueID: pr.Issue.ID,
  76. notificationAuthorID: r.Reviewer.ID,
  77. }
  78. if c != nil {
  79. opts.commentID = c.ID
  80. }
  81. ns.issueQueue <- opts
  82. }