1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 18:58:38 +00:00

some refactors for issue and comments (#2419)

This commit is contained in:
Lunny Xiao
2017-08-30 12:31:33 +08:00
committed by Lauris BH
parent edc817a1dc
commit 5de94a67cf
4 changed files with 30 additions and 14 deletions

View File

@@ -22,18 +22,18 @@ 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, comment *Comment, mentions []string) error {
func mailIssueCommentToParticipants(e Engine, issue *Issue, doer *User, comment *Comment, mentions []string) error {
if !setting.Service.EnableNotifyMail {
return nil
}
watchers, err := GetWatchers(issue.RepoID)
watchers, err := getWatchers(e, issue.RepoID)
if err != nil {
return fmt.Errorf("GetWatchers [repo_id: %d]: %v", issue.RepoID, err)
return fmt.Errorf("getWatchers [repo_id: %d]: %v", issue.RepoID, err)
}
participants, err := GetParticipantsByIssueID(issue.ID)
participants, err := getParticipantsByIssueID(e, issue.ID)
if err != nil {
return fmt.Errorf("GetParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err)
return fmt.Errorf("getParticipantsByIssueID [issue_id: %d]: %v", issue.ID, err)
}
// In case the issue poster is not watching the repository,
@@ -54,7 +54,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment,
continue
}
to, err := GetUserByID(watchers[i].UserID)
to, err := getUserByID(e, watchers[i].UserID)
if err != nil {
return fmt.Errorf("GetUserByID [%d]: %v", watchers[i].UserID, err)
}
@@ -88,7 +88,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment,
tos = append(tos, mentions[i])
}
SendIssueMentionMail(issue, doer, comment, GetUserEmailsByNames(tos))
SendIssueMentionMail(issue, doer, comment, getUserEmailsByNames(e, tos))
return nil
}
@@ -96,12 +96,16 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, comment *Comment,
// MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people.
func (issue *Issue) MailParticipants() (err error) {
return issue.mailParticipants(x)
}
func (issue *Issue) mailParticipants(e Engine) (err error) {
mentions := markdown.FindAllMentions(issue.Content)
if err = UpdateIssueMentions(x, issue.ID, mentions); err != nil {
if err = UpdateIssueMentions(e, issue.ID, mentions); err != nil {
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
}
if err = mailIssueCommentToParticipants(issue, issue.Poster, nil, mentions); err != nil {
if err = mailIssueCommentToParticipants(e, issue, issue.Poster, nil, mentions); err != nil {
log.Error(4, "mailIssueCommentToParticipants: %v", err)
}