This commit is contained in:
Andrey Nering
2016-12-05 19:14:52 -02:00
parent 75c2752ee6
commit c3810c6d43

View File

@@ -5,21 +5,29 @@ import (
) )
type ( type (
// NotificationStatus is the status of the notification (read or unread)
NotificationStatus uint8 NotificationStatus uint8
// NotificationSource is the source of the notification (issue, PR, commit, etc)
NotificationSource uint8 NotificationSource uint8
) )
const ( const (
// NotificationStatusUnread represents an unread notification
NotificationStatusUnread NotificationStatus = iota + 1 NotificationStatusUnread NotificationStatus = iota + 1
// NotificationStatusRead represents a read notification
NotificationStatusRead NotificationStatusRead
) )
const ( const (
// NotificationSourceIssue is a notification of an issue
NotificationSourceIssue NotificationSource = iota + 1 NotificationSourceIssue NotificationSource = iota + 1
// NotificationSourcePullRequest is a notification of a pull request
NotificationSourcePullRequest NotificationSourcePullRequest
// NotificationSourceCommit is a notification of a commit
NotificationSourceCommit NotificationSourceCommit
) )
// Notification represents a notification
type Notification struct { type Notification struct {
ID int64 `xorm:"pk autoincr"` ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"INDEX NOT NULL"` UserID int64 `xorm:"INDEX NOT NULL"`
@@ -41,6 +49,7 @@ type Notification struct {
UpdatedUnix int64 `xorm:"INDEX NOT NULL"` UpdatedUnix int64 `xorm:"INDEX NOT NULL"`
} }
// BeforeInsert runs while inserting a record
func (n *Notification) BeforeInsert() { func (n *Notification) BeforeInsert() {
var ( var (
now = time.Now() now = time.Now()
@@ -51,6 +60,8 @@ func (n *Notification) BeforeInsert() {
n.Updated = now n.Updated = now
n.UpdatedUnix = nowUnix n.UpdatedUnix = nowUnix
} }
// BeforeUpdate runs while updateing a record
func (n *Notification) BeforeUpdate() { func (n *Notification) BeforeUpdate() {
var ( var (
now = time.Now() now = time.Now()
@@ -60,6 +71,8 @@ func (n *Notification) BeforeUpdate() {
n.UpdatedUnix = nowUnix n.UpdatedUnix = nowUnix
} }
// CreateOrUpdateIssueNotifications creates an issue notification
// for each watcher, or updates it if already exists
func CreateOrUpdateIssueNotifications(issue *Issue) error { func CreateOrUpdateIssueNotifications(issue *Issue) error {
watches, err := getWatchers(x, issue.RepoID) watches, err := getWatchers(x, issue.RepoID)
if err != nil { if err != nil {
@@ -70,7 +83,6 @@ func CreateOrUpdateIssueNotifications(issue *Issue) error {
if err := sess.Begin(); err != nil { if err := sess.Begin(); err != nil {
return err return err
} }
defer sess.Close() defer sess.Close()
for _, watch := range watches { for _, watch := range watches {