Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

notification.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2016 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 notification
  5. import (
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/log"
  8. )
  9. type (
  10. notificationService struct {
  11. issueQueue chan issueNotificationOpts
  12. }
  13. issueNotificationOpts struct {
  14. issue *models.Issue
  15. notificationAuthorID int64
  16. }
  17. )
  18. var (
  19. // Service is the notification service
  20. Service = &notificationService{
  21. issueQueue: make(chan issueNotificationOpts, 100),
  22. }
  23. )
  24. func init() {
  25. go Service.Run()
  26. }
  27. func (ns *notificationService) Run() {
  28. for {
  29. select {
  30. case opts := <-ns.issueQueue:
  31. if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
  32. log.Error(4, "Was unable to create issue notification: %v", err)
  33. }
  34. }
  35. }
  36. }
  37. func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) {
  38. ns.issueQueue <- issueNotificationOpts{
  39. issue,
  40. notificationAuthorID,
  41. }
  42. }