1
0
Fork 0
forked from forgejo/forgejo

Improve notification (#8835)

* Improve notifications

* batch load user

* Update notification only when read

* Fix reorder

* fix lint

* fix test

* fix lint

* make function meaningful

* fix comment
This commit is contained in:
Lunny Xiao 2019-11-12 16:33:34 +08:00 committed by GitHub
parent 555b1f6581
commit bb6879d339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 299 additions and 36 deletions

View file

@ -18,7 +18,8 @@ type (
}
issueNotificationOpts struct {
issue *models.Issue
issueID int64
commentID int64
notificationAuthorID int64
}
)
@ -36,7 +37,7 @@ func NewNotifier() base.Notifier {
func (ns *notificationService) Run() {
for opts := range ns.issueQueue {
if err := models.CreateOrUpdateIssueNotifications(opts.issue, opts.notificationAuthorID); err != nil {
if err := models.CreateOrUpdateIssueNotifications(opts.issueID, opts.commentID, opts.notificationAuthorID); err != nil {
log.Error("Was unable to create issue notification: %v", err)
}
}
@ -44,43 +45,51 @@ func (ns *notificationService) Run() {
func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
issue *models.Issue, comment *models.Comment) {
ns.issueQueue <- issueNotificationOpts{
issue,
doer.ID,
var opts = issueNotificationOpts{
issueID: issue.ID,
notificationAuthorID: doer.ID,
}
if comment != nil {
opts.commentID = comment.ID
}
ns.issueQueue <- opts
}
func (ns *notificationService) NotifyNewIssue(issue *models.Issue) {
ns.issueQueue <- issueNotificationOpts{
issue,
issue.Poster.ID,
issueID: issue.ID,
notificationAuthorID: issue.Poster.ID,
}
}
func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
ns.issueQueue <- issueNotificationOpts{
issue,
doer.ID,
issueID: issue.ID,
notificationAuthorID: doer.ID,
}
}
func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, gitRepo *git.Repository) {
ns.issueQueue <- issueNotificationOpts{
pr.Issue,
doer.ID,
issueID: pr.Issue.ID,
notificationAuthorID: doer.ID,
}
}
func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
ns.issueQueue <- issueNotificationOpts{
pr.Issue,
pr.Issue.PosterID,
issueID: pr.Issue.ID,
notificationAuthorID: pr.Issue.PosterID,
}
}
func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) {
ns.issueQueue <- issueNotificationOpts{
pr.Issue,
r.Reviewer.ID,
var opts = issueNotificationOpts{
issueID: pr.Issue.ID,
notificationAuthorID: r.Reviewer.ID,
}
if c != nil {
opts.commentID = c.ID
}
ns.issueQueue <- opts
}