-
Notifications
You must be signed in to change notification settings - Fork 1
/
notification.go
50 lines (42 loc) · 1.05 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package notification
import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
)
type (
notificationService struct {
issueQueue chan issueNotificationOpts
}
issueNotificationOpts struct {
issue *models.Issue
notificationAuthorID int64
}
)
var (
// Service is the notification service
Service = ¬ificationService{
issueQueue: make(chan issueNotificationOpts, 100),
}
)
func init() {
go Service.Run()
}
func (ns *notificationService) Run() {
for {
select {
case opts := <-ns.issueQueue:
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
log.Error(4, "Was unable to create issue notification: %v", err)
}
}
}
}
func (ns *notificationService) NotifyIssue(issue *models.Issue, notificationAuthorID int64) {
ns.issueQueue <- issueNotificationOpts{
issue,
notificationAuthorID,
}
}