@@ -5,21 +5,29 @@ import (
5
5
)
6
6
7
7
type (
8
+ // NotificationStatus is the status of the notification (read or unread)
8
9
NotificationStatus uint8
10
+ // NotificationSource is the source of the notification (issue, PR, commit, etc)
9
11
NotificationSource uint8
10
12
)
11
13
12
14
const (
15
+ // NotificationStatusUnread represents an unread notification
13
16
NotificationStatusUnread NotificationStatus = iota + 1
17
+ // NotificationStatusRead represents a read notification
14
18
NotificationStatusRead
15
19
)
16
20
17
21
const (
22
+ // NotificationSourceIssue is a notification of an issue
18
23
NotificationSourceIssue NotificationSource = iota + 1
24
+ // NotificationSourcePullRequest is a notification of a pull request
19
25
NotificationSourcePullRequest
26
+ // NotificationSourceCommit is a notification of a commit
20
27
NotificationSourceCommit
21
28
)
22
29
30
+ // Notification represents a notification
23
31
type Notification struct {
24
32
ID int64 `xorm:"pk autoincr"`
25
33
UserID int64 `xorm:"INDEX NOT NULL"`
@@ -41,6 +49,7 @@ type Notification struct {
41
49
UpdatedUnix int64 `xorm:"INDEX NOT NULL"`
42
50
}
43
51
52
+ // BeforeInsert runs while inserting a record
44
53
func (n * Notification ) BeforeInsert () {
45
54
var (
46
55
now = time .Now ()
@@ -51,6 +60,8 @@ func (n *Notification) BeforeInsert() {
51
60
n .Updated = now
52
61
n .UpdatedUnix = nowUnix
53
62
}
63
+
64
+ // BeforeUpdate runs while updateing a record
54
65
func (n * Notification ) BeforeUpdate () {
55
66
var (
56
67
now = time .Now ()
@@ -60,6 +71,8 @@ func (n *Notification) BeforeUpdate() {
60
71
n .UpdatedUnix = nowUnix
61
72
}
62
73
74
+ // CreateOrUpdateIssueNotifications creates an issue notification
75
+ // for each watcher, or updates it if already exists
63
76
func CreateOrUpdateIssueNotifications (issue * Issue ) error {
64
77
watches , err := getWatchers (x , issue .RepoID )
65
78
if err != nil {
@@ -70,7 +83,6 @@ func CreateOrUpdateIssueNotifications(issue *Issue) error {
70
83
if err := sess .Begin (); err != nil {
71
84
return err
72
85
}
73
-
74
86
defer sess .Close ()
75
87
76
88
for _ , watch := range watches {
0 commit comments