From 03912ce0142039022481ccf3798ab937e9cf4f0b Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Thu, 25 May 2017 04:38:56 +0200 Subject: [PATCH] Adding #issuecomment to the URL in E-Mail notifications (#1674) * Added comment's hashtag to url for mail notifications. Signed-off-by: Jonas * Added comment's hashtag to url for mail notifications. Added explanation to return statement. Signed-off-by: Jonas * Added comment's hashtag to url for mail notifications. Added explanation to return statement + documentation. Signed-off-by: Jonas * Added comment's hashtag to url for mail notifications. Signed-off-by: Jonas Franz * Replacing in-line link generation with HTMLURL. (+gofmt) Signed-off-by: Jonas Franz * Replaced action-based model with nil-based model. (+gofmt) Signed-off-by: Jonas Franz * Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants. Signed-off-by: Jonas Franz * Updating comment for mailIssueCommentToParticipants Signed-off-by: Jonas Franz --- models/issue_comment.go | 4 ++-- models/issue_mail.go | 9 +++++---- models/mail.go | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index e133cc049..a65abfe01 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -153,7 +153,7 @@ func (c *Comment) HTMLURL() string { log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err) return "" } - return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID) + return fmt.Sprintf("%s#%s", issue.HTMLURL(), c.HashTag()) } // IssueURL formats a URL-string to the issue @@ -289,7 +289,7 @@ func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (e case ActionReopenIssue: issue.Content = fmt.Sprintf("Reopened #%d", issue.Index) } - if err = mailIssueCommentToParticipants(issue, c.Poster, mentions); err != nil { + if err = mailIssueCommentToParticipants(issue, c.Poster, c, mentions); err != nil { log.Error(4, "mailIssueCommentToParticipants: %v", err) } diff --git a/models/issue_mail.go b/models/issue_mail.go index 4b6542ddb..615aa82f0 100644 --- a/models/issue_mail.go +++ b/models/issue_mail.go @@ -22,7 +22,7 @@ func (issue *Issue) mailSubject() string { // This function sends two list of emails: // 1. Repository watchers and users who are participated in comments. // 2. Users who are not in 1. but get mentioned in current issue/comment. -func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error { +func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment, mentions []string) error { if !setting.Service.EnableNotifyMail { return nil } @@ -70,7 +70,8 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) tos = append(tos, participants[i].Email) names = append(names, participants[i].Name) } - SendIssueCommentMail(issue, doer, tos) + + SendIssueCommentMail(issue, doer, comment, tos) // Mail mentioned people and exclude watchers. names = append(names, doer.Name) @@ -82,7 +83,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) tos = append(tos, mentions[i]) } - SendIssueMentionMail(issue, doer, GetUserEmailsByNames(tos)) + SendIssueMentionMail(issue, doer, comment, GetUserEmailsByNames(tos)) return nil } @@ -95,7 +96,7 @@ func (issue *Issue) MailParticipants() (err error) { return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) } - if err = mailIssueCommentToParticipants(issue, issue.Poster, mentions); err != nil { + if err = mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions); err != nil { log.Error(4, "mailIssueCommentToParticipants: %v", err) } diff --git a/models/mail.go b/models/mail.go index 20ddde0cd..211f2b578 100644 --- a/models/mail.go +++ b/models/mail.go @@ -148,10 +148,16 @@ func composeTplData(subject, body, link string) map[string]interface{} { return data } -func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message { +func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message { subject := issue.mailSubject() body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas())) - data := composeTplData(subject, body, issue.HTMLURL()) + + data := make(map[string]interface{}, 10) + if comment != nil { + data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag()) + } else { + data = composeTplData(subject, body, issue.HTMLURL()) + } data["Doer"] = doer var content bytes.Buffer @@ -166,18 +172,18 @@ func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []s } // SendIssueCommentMail composes and sends issue comment emails to target receivers. -func SendIssueCommentMail(issue *Issue, doer *User, tos []string) { +func SendIssueCommentMail(issue *Issue, doer *User, comment *Comment, tos []string) { if len(tos) == 0 { return } - mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueComment, tos, "issue comment")) + mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueComment, tos, "issue comment")) } // SendIssueMentionMail composes and sends issue mention emails to target receivers. -func SendIssueMentionMail(issue *Issue, doer *User, tos []string) { +func SendIssueMentionMail(issue *Issue, doer *User, comment *Comment, tos []string) { if len(tos) == 0 { return } - mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention")) + mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueMention, tos, "issue mention")) }