summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-12-09 11:30:01 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-12-09 16:38:55 -0500
commit83b46880f3fb724042e713b9195857568646463c (patch)
treecf7c8754e705bebd85976b1db266f93b9bf2b21d /api
parent985dc06e5fb9d809e4be4e5fff2c3b1ca66c1ea9 (diff)
downloadchat-83b46880f3fb724042e713b9195857568646463c.tar.gz
chat-83b46880f3fb724042e713b9195857568646463c.tar.bz2
chat-83b46880f3fb724042e713b9195857568646463c.zip
Changed serverside mention parsing to support usernames containing periods
Diffstat (limited to 'api')
-rw-r--r--api/post.go53
1 files changed, 35 insertions, 18 deletions
diff --git a/api/post.go b/api/post.go
index 6736d75e2..f3b8d00e4 100644
--- a/api/post.go
+++ b/api/post.go
@@ -432,35 +432,52 @@ func sendNotificationsAndForget(c *Context, post *model.Post, team *model.Team,
splitF := func(c rune) bool {
return model.SplitRunes[c]
}
- splitMessage := strings.FieldsFunc(post.Message, splitF)
+ splitMessage := strings.Fields(post.Message)
for _, word := range splitMessage {
+ var userIds []string
// Non-case-sensitive check for regular keys
- userIds1, keyMatch := keywordMap[strings.ToLower(word)]
+ if ids, match := keywordMap[strings.ToLower(word)]; match {
+ userIds = append(userIds, ids...)
+ }
// Case-sensitive check for first name
- userIds2, firstNameMatch := keywordMap[word]
+ if ids, match := keywordMap[word]; match {
+ userIds = append(userIds, ids...)
+ }
- userIds := append(userIds1, userIds2...)
+ if len(userIds) == 0 {
+ // No matches were found with the string split just on whitespace so try further splitting
+ // the message on punctuation
+ splitWords := strings.FieldsFunc(word, splitF)
- // If one of the non-case-senstive keys or the first name matches the word
- // then we add en entry to the sendEmail map
- if keyMatch || firstNameMatch {
- for _, userId := range userIds {
- if post.UserId == userId {
- continue
- }
- sendEmail := true
- if _, ok := profileMap[userId].NotifyProps["email"]; ok && profileMap[userId].NotifyProps["email"] == "false" {
- sendEmail = false
+ for _, splitWord := range splitWords {
+ // Non-case-sensitive check for regular keys
+ if ids, match := keywordMap[strings.ToLower(splitWord)]; match {
+ userIds = append(userIds, ids...)
}
- if sendEmail && (profileMap[userId].IsAway() || profileMap[userId].IsOffline()) {
- toEmailMap[userId] = true
- } else {
- toEmailMap[userId] = false
+
+ // Case-sensitive check for first name
+ if ids, match := keywordMap[splitWord]; match {
+ userIds = append(userIds, ids...)
}
}
}
+
+ for _, userId := range userIds {
+ if post.UserId == userId {
+ continue
+ }
+ sendEmail := true
+ if _, ok := profileMap[userId].NotifyProps["email"]; ok && profileMap[userId].NotifyProps["email"] == "false" {
+ sendEmail = false
+ }
+ if sendEmail && (profileMap[userId].IsAway() || profileMap[userId].IsOffline()) {
+ toEmailMap[userId] = true
+ } else {
+ toEmailMap[userId] = false
+ }
+ }
}
for id := range toEmailMap {