diff options
author | Jimmy Praet <jimmy.praet@telenet.be> | 2021-01-02 18:04:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 18:04:02 +0100 |
commit | e6acce649b348cc497b999100a170866a90c87b8 (patch) | |
tree | 2a1bb838fe8b36f016c638190651e61e6b27acd3 /models | |
parent | ac88b0ee839bfbfae5759e211d0f9a69abe4d8f7 (diff) | |
download | gitea-e6acce649b348cc497b999100a170866a90c87b8.tar.gz gitea-e6acce649b348cc497b999100a170866a90c87b8.zip |
Send notifications for mentions in pulls, issues, (code-)comments (#14218)
Fixes #14187: mention handling extracted from email notification code
Fixes #14013: add notification for mentions in pull request code comments
Fixes #13450: Not receiving any emails with setting "Only Email on Mention"
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go index eb47a74091..18d01d57d4 100644 --- a/models/issue.go +++ b/models/issue.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/references" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" api "code.gitea.io/gitea/modules/structs" @@ -1848,6 +1849,19 @@ func (issue *Issue) updateClosedNum(e Engine) (err error) { return } +// FindAndUpdateIssueMentions finds users mentioned in the given content string, and saves them in the database. +func (issue *Issue) FindAndUpdateIssueMentions(ctx DBContext, doer *User, content string) (mentions []*User, err error) { + rawMentions := references.FindAllMentionsMarkdown(content) + mentions, err = issue.ResolveMentionsByVisibility(ctx, doer, rawMentions) + if err != nil { + return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) + } + if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil { + return nil, fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err) + } + return +} + // ResolveMentionsByVisibility returns the users mentioned in an issue, removing those that // don't have access to reading it. Teams are expanded into their users, but organizations are ignored. func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, mentions []string) (users []*User, err error) { |