summaryrefslogtreecommitdiffstats
path: root/app/notification.go
diff options
context:
space:
mode:
authorPradeep Murugesan <pradeepmurugesan@outlook.com>2018-07-11 16:11:36 +0200
committerHarrison Healey <harrisonmhealey@gmail.com>2018-07-11 10:11:36 -0400
commit06abe98ba90a092b4f788fa2c16c204f5bc0efcd (patch)
treee2aaf767c3410a0823fa5919162500b0dc9c5600 /app/notification.go
parent5b63e87ab7aae4d27b492ff25b6786924d4c6dcc (diff)
downloadchat-06abe98ba90a092b4f788fa2c16c204f5bc0efcd.tar.gz
chat-06abe98ba90a092b4f788fa2c16c204f5bc0efcd.tar.bz2
chat-06abe98ba90a092b4f788fa2c16c204f5bc0efcd.zip
GH-8964 enable notification for text and preText fields in Attachments (#9069)
Diffstat (limited to 'app/notification.go')
-rw-r--r--app/notification.go45
1 files changed, 33 insertions, 12 deletions
diff --git a/app/notification.go b/app/notification.go
index 2ba585f3b..8da581c00 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -94,7 +94,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
} else {
keywords := a.GetMentionKeywordsInChannel(profileMap, post.Type != model.POST_HEADER_CHANGE && post.Type != model.POST_PURPOSE_CHANGE)
- m := GetExplicitMentions(post.Message, keywords)
+ m := GetExplicitMentions(post, keywords)
// Add an implicit mention when a user is added to a channel
// even if the user has set 'username mentions' to false in account settings.
@@ -961,7 +961,7 @@ type ExplicitMentions struct {
// Given a message and a map mapping mention keywords to the users who use them, returns a map of mentioned
// users and a slice of potential mention users not in the channel and whether or not @here was mentioned.
-func GetExplicitMentions(message string, keywords map[string][]string) *ExplicitMentions {
+func GetExplicitMentions(post *model.Post, keywords map[string][]string) *ExplicitMentions {
ret := &ExplicitMentions{
MentionedUserIds: make(map[string]bool),
}
@@ -1053,21 +1053,42 @@ func GetExplicitMentions(message string, keywords map[string][]string) *Explicit
}
buf := ""
- markdown.Inspect(message, func(node interface{}) bool {
- text, ok := node.(*markdown.Text)
- if !ok {
- processText(buf)
- buf = ""
- return true
- }
- buf += text.Text
- return false
- })
+ mentionsEnabledFields := GetMentionsEnabledFields(post)
+ for _, message := range mentionsEnabledFields {
+ markdown.Inspect(message, func(node interface{}) bool {
+ text, ok := node.(*markdown.Text)
+ if !ok {
+ processText(buf)
+ buf = ""
+ return true
+ }
+ buf += text.Text
+ return false
+ })
+ }
processText(buf)
return ret
}
+// Given a post returns the values of the fields in which mentions are possible.
+// post.message, preText and text in the attachment are enabled.
+func GetMentionsEnabledFields(post *model.Post) model.StringArray {
+ ret := []string{}
+
+ ret = append(ret, post.Message)
+ for _, attachment := range post.Attachments() {
+
+ if len(attachment.Pretext) != 0 {
+ ret = append(ret, attachment.Pretext)
+ }
+ if len(attachment.Text) != 0 {
+ ret = append(ret, attachment.Text)
+ }
+ }
+ return ret
+}
+
// Given a map of user IDs to profiles, returns a list of mention
// keywords for all users in the channel.
func (a *App) GetMentionKeywordsInChannel(profiles map[string]*model.User, lookForSpecialMentions bool) map[string][]string {