Merge branch 'ICU-764' into release-4.7

Этот коммит содержится в:
Derrick Anderson
2018-02-14 00:48:30 -05:00
родитель 963150b6ec 69e56fc042
Коммит 50b648156c
2 изменённых файлов: 81 добавлений и 45 удалений

Просмотреть файл

@@ -819,19 +819,9 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
ret.MentionedUserIds[id] = true ret.MentionedUserIds[id] = true
} }
} }
checkForMention := func(word string) bool {
processText := func(text string) {
for _, word := range strings.FieldsFunc(text, func(c rune) bool {
// Split on any whitespace or punctuation that can't be part of an at mention or emoji pattern
return !(c == ':' || c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
}) {
isMention := false isMention := false
// skip word with format ':word:' with an assumption that it is an emoji format only
if word[0] == ':' && word[len(word)-1] == ':' {
continue
}
if word == "@here" { if word == "@here" {
ret.HereMentioned = true ret.HereMentioned = true
} }
@@ -856,7 +846,25 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
isMention = true isMention = true
} }
if isMention { return isMention
}
processText := func(text string) {
for _, word := range strings.FieldsFunc(text, func(c rune) bool {
// Split on any whitespace or punctuation that can't be part of an at mention or emoji pattern
return !(c == ':' || c == '.' || c == '-' || c == '_' || c == '@' || unicode.IsLetter(c) || unicode.IsNumber(c))
}) {
// skip word with format ':word:' with an assumption that it is an emoji format only
if word[0] == ':' && word[len(word)-1] == ':' {
continue
}
if checkForMention(word) {
continue
}
// remove trailing '.', as that is the end of a sentence
word = strings.TrimSuffix(word, ".")
if checkForMention(word) {
continue continue
} }
@@ -867,27 +875,10 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
}) })
for _, splitWord := range splitWords { for _, splitWord := range splitWords {
if splitWord == "@here" { if checkForMention(splitWord) {
ret.HereMentioned = true continue
} }
if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
if splitWord == "@all" {
ret.AllMentioned = true
}
if splitWord == "@channel" {
ret.ChannelMentioned = true
}
// Non-case-sensitive check for regular keys
if ids, match := keywords[strings.ToLower(splitWord)]; match {
addMentionedUsers(ids)
}
// Case-sensitive check for first name
if ids, match := keywords[splitWord]; match {
addMentionedUsers(ids)
} else if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
username := splitWord[1:] username := splitWord[1:]
ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, username) ret.OtherPotentialMentions = append(ret.OtherPotentialMentions, username)
} }

Просмотреть файл

@@ -109,6 +109,33 @@ func TestGetExplicitMentions(t *testing.T) {
}, },
}, },
}, },
"OnePersonWithPeriodAtEndOfUsername": {
Message: "this is a message for @user.name.",
Keywords: map[string][]string{"@user.name.": {id1}},
Expected: &ExplicitMentions{
MentionedUserIds: map[string]bool{
id1: true,
},
},
},
"OnePersonWithPeriodAtEndOfUsernameButNotSimilarName": {
Message: "this is a message for @user.name.",
Keywords: map[string][]string{"@user.name.": {id1}, "@user.name": {id2}},
Expected: &ExplicitMentions{
MentionedUserIds: map[string]bool{
id1: true,
},
},
},
"OnePersonAtEndOfSentence": {
Message: "this is a message for @user.",
Keywords: map[string][]string{"@user": {id1}},
Expected: &ExplicitMentions{
MentionedUserIds: map[string]bool{
id1: true,
},
},
},
"OnePersonWithoutAtMention": { "OnePersonWithoutAtMention": {
Message: "this is a message for @user", Message: "this is a message for @user",
Keywords: map[string][]string{"this": {id1}}, Keywords: map[string][]string{"this": {id1}},
@@ -179,6 +206,24 @@ func TestGetExplicitMentions(t *testing.T) {
}, },
}, },
}, },
"AtUserWithPeriodAtEndOfSentence": {
Message: "this is a message for @user.period.",
Keywords: map[string][]string{"@user.period": {id1}},
Expected: &ExplicitMentions{
MentionedUserIds: map[string]bool{
id1: true,
},
},
},
"UserWithPeriodAtEndOfSentence": {
Message: "this is a message for user.period.",
Keywords: map[string][]string{"user.period": {id1}},
Expected: &ExplicitMentions{
MentionedUserIds: map[string]bool{
id1: true,
},
},
},
"PotentialOutOfChannelUser": { "PotentialOutOfChannelUser": {
Message: "this is an message for @potential and @user", Message: "this is an message for @potential and @user",
Keywords: map[string][]string{"@user": {id1}}, Keywords: map[string][]string{"@user": {id1}},