mirror of
https://github.com/mattermost/focalboard.git
synced 2024-12-12 09:04:14 +02:00
35 lines
882 B
Go
35 lines
882 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package notifymentions
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
|
)
|
|
|
|
var atMentionRegexp = regexp.MustCompile(`\B@[[:alnum:]][[:alnum:]\.\-_:]*`)
|
|
|
|
// extractMentions extracts any mentions in the specified block and returns
|
|
// a slice of usernames.
|
|
func extractMentions(block *model.Block) map[string]struct{} {
|
|
mentions := make(map[string]struct{})
|
|
if block == nil || !strings.Contains(block.Title, "@") {
|
|
return mentions
|
|
}
|
|
|
|
str := block.Title
|
|
|
|
for _, match := range atMentionRegexp.FindAllString(str, -1) {
|
|
name := mm_model.NormalizeUsername(match[1:])
|
|
if mm_model.IsValidUsernameAllowRemote(name) {
|
|
mentions[name] = struct{}{}
|
|
}
|
|
}
|
|
return mentions
|
|
}
|