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.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/log"
  8. "code.gitea.io/gitea/modules/notification/base"
  9. )
  10. type (
  11. notificationService struct {
  12. base.NullNotifier
  13. issueQueue chan issueNotificationOpts
  14. }
  15. issueNotificationOpts struct {
  16. issueID int64
  17. commentID int64
  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.issueID, opts.commentID, 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. var opts = issueNotificationOpts{
  40. issueID: issue.ID,
  41. notificationAuthorID: doer.ID,
  42. }
  43. if comment != nil {
  44. opts.commentID = comment.ID
  45. }
  46. ns.issueQueue <- opts
  47. }
  48. func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
  49. ns.issueQueue <- issueNotificationOpts{
  50. issueID: issue.ID,
  51. notificationAuthorID: issue.Poster.ID,
  52. }
  53. }
  54. func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) {
  55. ns.issueQueue <- issueNotificationOpts{
  56. issueID: issue.ID,
  57. notificationAuthorID: doer.ID,
  58. }
  59. }
  60. func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) {
  61. ns.issueQueue <- issueNotificationOpts{
  62. issueID: pr.Issue.ID,
  63. notificationAuthorID: doer.ID,
  64. }
  65. }
  66. func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
  67. ns.issueQueue <- issueNotificationOpts{
  68. issueID: pr.Issue.ID,
  69. notificationAuthorID: pr.Issue.PosterID,
  70. }
  71. }
  72. func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
  73. var opts = issueNotificationOpts{
  74. issueID: pr.Issue.ID,
  75. notificationAuthorID: r.Reviewer.ID,
  76. }
  77. if c != nil {
  78. opts.commentID = c.ID
  79. }
  80. ns.issueQueue <- opts
  81. }