Move some variables out of model (#17909)
* Move some variables out of model There were some stuff that's not necessary to be in model and can just remain unexported variables. ```release-note NONE ``` * Add license ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
97ccf0bdf6
Коммит
f49b5dc440
@@ -10,6 +10,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"unicode"
|
||||
@@ -23,8 +24,11 @@ import (
|
||||
|
||||
const (
|
||||
CmdCustomStatusTrigger = "status"
|
||||
usernameSpecialChars = ".-_"
|
||||
)
|
||||
|
||||
var atMentionRegexp = regexp.MustCompile(`\B@[[:alnum:]][[:alnum:]\.\-_:]*`)
|
||||
|
||||
type CommandProvider interface {
|
||||
GetTrigger() string
|
||||
GetCommand(a *App, T i18n.TranslateFunc) *model.Command
|
||||
@@ -233,7 +237,7 @@ func (a *App) MentionsToTeamMembers(message, teamID string) model.UserMentionMap
|
||||
Id string
|
||||
}
|
||||
|
||||
possibleMentions := model.PossibleAtMentions(message)
|
||||
possibleMentions := possibleAtMentions(message)
|
||||
mentionChan := make(chan *mentionMapItem, len(possibleMentions))
|
||||
|
||||
var wg sync.WaitGroup
|
||||
@@ -252,8 +256,8 @@ func (a *App) MentionsToTeamMembers(message, teamID string) model.UserMentionMap
|
||||
// If it's a http.StatusNotFound error, check for usernames in substrings
|
||||
// without trailing punctuation
|
||||
if nErr != nil {
|
||||
trimmed, ok := model.TrimUsernameSpecialChar(mention)
|
||||
for ; ok; trimmed, ok = model.TrimUsernameSpecialChar(trimmed) {
|
||||
trimmed, ok := trimUsernameSpecialChar(mention)
|
||||
for ; ok; trimmed, ok = trimUsernameSpecialChar(trimmed) {
|
||||
userFromTrimmed, nErr := a.Srv().Store.User().GetByUsername(trimmed)
|
||||
if nErr != nil && !errors.As(nErr, &nfErr) {
|
||||
return
|
||||
@@ -770,3 +774,37 @@ func (a *App) DeleteCommand(commandID string) *model.AppError {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// possibleAtMentions returns all substrings in message that look like valid @
|
||||
// mentions.
|
||||
func possibleAtMentions(message string) []string {
|
||||
var names []string
|
||||
|
||||
if !strings.Contains(message, "@") {
|
||||
return names
|
||||
}
|
||||
|
||||
alreadyMentioned := make(map[string]bool)
|
||||
for _, match := range atMentionRegexp.FindAllString(message, -1) {
|
||||
name := model.NormalizeUsername(match[1:])
|
||||
if !alreadyMentioned[name] && model.IsValidUsernameAllowRemote(name) {
|
||||
names = append(names, name)
|
||||
alreadyMentioned[name] = true
|
||||
}
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
// trimUsernameSpecialChar tries to remove the last character from word if it
|
||||
// is a special character for usernames (dot, dash or underscore). If not, it
|
||||
// returns the same string.
|
||||
func trimUsernameSpecialChar(word string) (string, bool) {
|
||||
len := len(word)
|
||||
|
||||
if len > 0 && strings.LastIndexAny(word, usernameSpecialChars) == (len-1) {
|
||||
return word[:len-1], true
|
||||
}
|
||||
|
||||
return word, false
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user