add deletecomment notify

This commit is contained in:
Lunny Xiao 2018-05-21 23:00:18 +08:00
parent 3888095a74
commit 81661c2b47
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
10 changed files with 56 additions and 26 deletions

View File

@ -728,6 +728,15 @@ func UpdateComment(doer *User, c *Comment) error {
return nil
}
// UpdateCommentAction updates action when comment is deleted
func UpdateCommentAction(comment *Comment) error {
if _, err := x.Where("comment_id = ?", comment.ID).
Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil {
return err
}
return nil
}
// DeleteComment deletes the comment
func DeleteComment(doer *User, comment *Comment) error {
sess := x.NewSession()
@ -747,35 +756,9 @@ func DeleteComment(doer *User, comment *Comment) error {
return err
}
}
if _, err := sess.Where("comment_id = ?", comment.ID).Cols("is_deleted").Update(&Action{IsDeleted: true}); err != nil {
return err
}
if err := sess.Commit(); err != nil {
return err
} else if comment.Type == CommentTypeComment {
UpdateIssueIndexer(comment.IssueID)
}
if err := comment.LoadIssue(); err != nil {
return err
}
if err := comment.Issue.LoadAttributes(); err != nil {
return err
}
mode, _ := AccessLevel(doer.ID, comment.Issue.Repo)
if err := PrepareWebhooks(comment.Issue.Repo, HookEventIssueComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentDeleted,
Issue: comment.Issue.APIFormat(),
Comment: comment.APIFormat(),
Repository: comment.Issue.Repo.APIFormat(mode),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
go HookQueue.Add(comment.Issue.Repo.ID)
}
return nil

View File

@ -73,3 +73,9 @@ func (r *actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mo
func (r *actionNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
}
func (r *actionNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
if err := models.UpdateCommentAction(c); err != nil {
log.Error(4, "UpdateCommentAction [%d]: %v", c.ID, err)
}
}

View File

@ -19,4 +19,5 @@ type Notifier interface {
NotifyMergePullRequest(*models.PullRequest, *models.User, *git.Repository)
NotifyNewPullRequest(*models.PullRequest)
NotifyUpdateComment(*models.User, *models.Comment, string)
NotifyDeleteComment(*models.User, *models.Comment)
}

View File

@ -49,3 +49,9 @@ func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
models.UpdateIssueIndexer(c.IssueID)
}
}
func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
if comment.Type == models.CommentTypeComment {
models.UpdateIssueIndexer(comment.IssueID)
}
}

View File

@ -54,3 +54,6 @@ func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
func (m *mailNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
}
func (m *mailNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
}

View File

@ -75,3 +75,10 @@ func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string
notifier.NotifyUpdateComment(doer, c, oldContent)
}
}
// NotifyDeleteComment notifies update comment to notifiers
func NotifyDeleteComment(doer *models.User, c *models.Comment) {
for _, notifier := range notifiers {
notifier.NotifyDeleteComment(doer, c)
}
}

View File

@ -78,3 +78,6 @@ func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) {
func (ns *notificationService) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
}
func (ns *notificationService) NotifyDeleteComment(doer *models.User, c *models.Comment) {
}

View File

@ -155,3 +155,19 @@ func (w *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
go models.HookQueue.Add(c.Issue.Repo.ID)
}
}
func (w *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) {
mode, _ := models.AccessLevel(doer.ID, comment.Issue.Repo)
if err := models.PrepareWebhooks(comment.Issue.Repo, models.HookEventIssueComment, &api.IssueCommentPayload{
Action: api.HookIssueCommentDeleted,
Issue: comment.Issue.APIFormat(),
Comment: comment.APIFormat(),
Repository: comment.Issue.Repo.APIFormat(mode),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(2, "PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
} else {
go models.HookQueue.Add(comment.Issue.Repo.ID)
}
}

View File

@ -359,5 +359,8 @@ func deleteIssueComment(ctx *context.APIContext) {
ctx.Error(500, "DeleteCommentByID", err)
return
}
notification.NotifyDeleteComment(ctx.User, comment)
ctx.Status(204)
}

View File

@ -1127,6 +1127,8 @@ func DeleteComment(ctx *context.Context) {
return
}
notification.NotifyDeleteComment(ctx.User, comment)
ctx.Status(200)
}