From e6acce649b348cc497b999100a170866a90c87b8 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Sat, 2 Jan 2021 18:04:02 +0100 Subject: 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" --- models/issue.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'models/issue.go') 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) { -- cgit v1.2.3