Browse Source

Adding #issuecomment to the URL in E-Mail notifications (#1674)

* Added comment's hashtag to url for mail notifications.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.
Added explanation to return statement.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.
Added explanation to return statement + documentation.

Signed-off-by: Jonas <info@jonasfranz.software>

* Added comment's hashtag to url for mail notifications.

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replacing in-line link generation with HTMLURL. (+gofmt)

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replaced action-based model with nil-based model. (+gofmt)

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Replaced mailIssueActionToParticipants with mailIssueCommentToParticipants.

Signed-off-by: Jonas Franz <info@jonasfranz.software>

* Updating comment for mailIssueCommentToParticipants

Signed-off-by: Jonas Franz <info@jonasfranz.software>
Jonas Franz 3 years ago
parent
commit
03912ce014
3 changed files with 19 additions and 12 deletions
  1. 2 2
      models/issue_comment.go
  2. 5 4
      models/issue_mail.go
  3. 12 6
      models/mail.go

+ 2 - 2
models/issue_comment.go

@@ -153,7 +153,7 @@ func (c *Comment) HTMLURL() string {
153 153
 		log.Error(4, "GetIssueByID(%d): %v", c.IssueID, err)
154 154
 		return ""
155 155
 	}
156
-	return fmt.Sprintf("%s#issuecomment-%d", issue.HTMLURL(), c.ID)
156
+	return fmt.Sprintf("%s#%s", issue.HTMLURL(), c.HashTag())
157 157
 }
158 158
 
159 159
 // IssueURL formats a URL-string to the issue
@@ -289,7 +289,7 @@ func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (e
289 289
 	case ActionReopenIssue:
290 290
 		issue.Content = fmt.Sprintf("Reopened #%d", issue.Index)
291 291
 	}
292
-	if err = mailIssueCommentToParticipants(issue, c.Poster, mentions); err != nil {
292
+	if err = mailIssueCommentToParticipants(issue, c.Poster, c, mentions); err != nil {
293 293
 		log.Error(4, "mailIssueCommentToParticipants: %v", err)
294 294
 	}
295 295
 

+ 5 - 4
models/issue_mail.go

@@ -22,7 +22,7 @@ func (issue *Issue) mailSubject() string {
22 22
 // This function sends two list of emails:
23 23
 // 1. Repository watchers and users who are participated in comments.
24 24
 // 2. Users who are not in 1. but get mentioned in current issue/comment.
25
-func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string) error {
25
+func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment, mentions []string) error {
26 26
 	if !setting.Service.EnableNotifyMail {
27 27
 		return nil
28 28
 	}
@@ -70,7 +70,8 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
70 70
 		tos = append(tos, participants[i].Email)
71 71
 		names = append(names, participants[i].Name)
72 72
 	}
73
-	SendIssueCommentMail(issue, doer, tos)
73
+
74
+	SendIssueCommentMail(issue, doer, comment, tos)
74 75
 
75 76
 	// Mail mentioned people and exclude watchers.
76 77
 	names = append(names, doer.Name)
@@ -82,7 +83,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
82 83
 
83 84
 		tos = append(tos, mentions[i])
84 85
 	}
85
-	SendIssueMentionMail(issue, doer, GetUserEmailsByNames(tos))
86
+	SendIssueMentionMail(issue, doer, comment, GetUserEmailsByNames(tos))
86 87
 
87 88
 	return nil
88 89
 }
@@ -95,7 +96,7 @@ func (issue *Issue) MailParticipants() (err error) {
95 96
 		return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
96 97
 	}
97 98
 
98
-	if err = mailIssueCommentToParticipants(issue, issue.Poster, mentions); err != nil {
99
+	if err = mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions); err != nil {
99 100
 		log.Error(4, "mailIssueCommentToParticipants: %v", err)
100 101
 	}
101 102
 

+ 12 - 6
models/mail.go

@@ -148,10 +148,16 @@ func composeTplData(subject, body, link string) map[string]interface{} {
148 148
 	return data
149 149
 }
150 150
 
151
-func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []string, info string) *mailer.Message {
151
+func composeIssueCommentMessage(issue *Issue, doer *User, comment *Comment, tplName base.TplName, tos []string, info string) *mailer.Message {
152 152
 	subject := issue.mailSubject()
153 153
 	body := string(markdown.RenderString(issue.Content, issue.Repo.HTMLURL(), issue.Repo.ComposeMetas()))
154
-	data := composeTplData(subject, body, issue.HTMLURL())
154
+
155
+	data := make(map[string]interface{}, 10)
156
+	if comment != nil {
157
+		data = composeTplData(subject, body, issue.HTMLURL()+"#"+comment.HashTag())
158
+	} else {
159
+		data = composeTplData(subject, body, issue.HTMLURL())
160
+	}
155 161
 	data["Doer"] = doer
156 162
 
157 163
 	var content bytes.Buffer
@@ -166,18 +172,18 @@ func composeIssueMessage(issue *Issue, doer *User, tplName base.TplName, tos []s
166 172
 }
167 173
 
168 174
 // SendIssueCommentMail composes and sends issue comment emails to target receivers.
169
-func SendIssueCommentMail(issue *Issue, doer *User, tos []string) {
175
+func SendIssueCommentMail(issue *Issue, doer *User, comment *Comment, tos []string) {
170 176
 	if len(tos) == 0 {
171 177
 		return
172 178
 	}
173 179
 
174
-	mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueComment, tos, "issue comment"))
180
+	mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueComment, tos, "issue comment"))
175 181
 }
176 182
 
177 183
 // SendIssueMentionMail composes and sends issue mention emails to target receivers.
178
-func SendIssueMentionMail(issue *Issue, doer *User, tos []string) {
184
+func SendIssueMentionMail(issue *Issue, doer *User, comment *Comment, tos []string) {
179 185
 	if len(tos) == 0 {
180 186
 		return
181 187
 	}
182
-	mailer.SendAsync(composeIssueMessage(issue, doer, mailIssueMention, tos, "issue mention"))
188
+	mailer.SendAsync(composeIssueCommentMessage(issue, doer, comment, mailIssueMention, tos, "issue mention"))
183 189
 }