From c3810c6d43ea2d6656eb59caa62982e8f97c1160 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Mon, 5 Dec 2016 19:14:52 -0200 Subject: [PATCH] Lint --- models/notification.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/models/notification.go b/models/notification.go index d5ebab78e..44d838fe1 100644 --- a/models/notification.go +++ b/models/notification.go @@ -5,21 +5,29 @@ import ( ) type ( + // NotificationStatus is the status of the notification (read or unread) NotificationStatus uint8 + // NotificationSource is the source of the notification (issue, PR, commit, etc) NotificationSource uint8 ) const ( + // NotificationStatusUnread represents an unread notification NotificationStatusUnread NotificationStatus = iota + 1 + // NotificationStatusRead represents a read notification NotificationStatusRead ) const ( + // NotificationSourceIssue is a notification of an issue NotificationSourceIssue NotificationSource = iota + 1 + // NotificationSourcePullRequest is a notification of a pull request NotificationSourcePullRequest + // NotificationSourceCommit is a notification of a commit NotificationSourceCommit ) +// Notification represents a notification type Notification struct { ID int64 `xorm:"pk autoincr"` UserID int64 `xorm:"INDEX NOT NULL"` @@ -41,6 +49,7 @@ type Notification struct { UpdatedUnix int64 `xorm:"INDEX NOT NULL"` } +// BeforeInsert runs while inserting a record func (n *Notification) BeforeInsert() { var ( now = time.Now() @@ -51,6 +60,8 @@ func (n *Notification) BeforeInsert() { n.Updated = now n.UpdatedUnix = nowUnix } + +// BeforeUpdate runs while updateing a record func (n *Notification) BeforeUpdate() { var ( now = time.Now() @@ -60,6 +71,8 @@ func (n *Notification) BeforeUpdate() { n.UpdatedUnix = nowUnix } +// CreateOrUpdateIssueNotifications creates an issue notification +// for each watcher, or updates it if already exists func CreateOrUpdateIssueNotifications(issue *Issue) error { watches, err := getWatchers(x, issue.RepoID) if err != nil { @@ -70,7 +83,6 @@ func CreateOrUpdateIssueNotifications(issue *Issue) error { if err := sess.Begin(); err != nil { return err } - defer sess.Close() for _, watch := range watches {