diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-12 16:33:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-12 16:33:34 +0800 |
commit | bb6879d339d83e598a3d9f0974734cd591394369 (patch) | |
tree | bc2f40210a5c7a7f30b620fb7fd1efc6ca7ffc07 /modules | |
parent | 555b1f658198449670c77839bccf010e33ca74db (diff) | |
download | gitea-bb6879d339d83e598a3d9f0974734cd591394369.tar.gz gitea-bb6879d339d83e598a3d9f0974734cd591394369.zip |
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
Diffstat (limited to 'modules')
-rw-r--r-- | modules/notification/ui/ui.go | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index 22089158f5..bfe497f866 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -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 } |