PLT-7509 Stopped processing special mentions for change of header/purpose messages (#7410)

This commit is contained in:
Harrison Healey
2017-09-15 08:37:29 -04:00
committed by Joram Wilander
parent 2be5577b88
commit 2a6cd44f23
2 changed files with 39 additions and 14 deletions

View File

@@ -71,7 +71,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
mentionedUserIds[post.UserId] = true
}
} else {
keywords := GetMentionKeywordsInChannel(profileMap)
keywords := GetMentionKeywordsInChannel(profileMap, post.Type != model.POST_HEADER_CHANGE && post.Type != model.POST_PURPOSE_CHANGE)
var potentialOtherMentions []string
mentionedUserIds, potentialOtherMentions, hereNotification, channelNotification, allNotification = GetExplicitMentions(post.Message, keywords)
@@ -873,7 +873,7 @@ func removeCodeFromMessage(message string) string {
// Given a map of user IDs to profiles, returns a list of mention
// keywords for all users in the channel.
func GetMentionKeywordsInChannel(profiles map[string]*model.User) map[string][]string {
func GetMentionKeywordsInChannel(profiles map[string]*model.User, lookForSpecialMentions bool) map[string][]string {
keywords := make(map[string][]string)
for id, profile := range profiles {
@@ -896,13 +896,15 @@ func GetMentionKeywordsInChannel(profiles map[string]*model.User) map[string][]s
}
// Add @channel and @all to keywords if user has them turned on
if int64(len(profiles)) < *utils.Cfg.TeamSettings.MaxNotificationsPerChannel && profile.NotifyProps["channel"] == "true" {
keywords["@channel"] = append(keywords["@channel"], profile.Id)
keywords["@all"] = append(keywords["@all"], profile.Id)
if lookForSpecialMentions {
if int64(len(profiles)) < *utils.Cfg.TeamSettings.MaxNotificationsPerChannel && profile.NotifyProps["channel"] == "true" {
keywords["@channel"] = append(keywords["@channel"], profile.Id)
keywords["@all"] = append(keywords["@all"], profile.Id)
status := GetStatusFromCache(profile.Id)
if status != nil && status.Status == model.STATUS_ONLINE {
keywords["@here"] = append(keywords["@here"], profile.Id)
status := GetStatusFromCache(profile.Id)
if status != nil && status.Status == model.STATUS_ONLINE {
keywords["@here"] = append(keywords["@here"], profile.Id)
}
}
}
}

View File

@@ -420,7 +420,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles := map[string]*model.User{user1.Id: user1}
mentions := GetMentionKeywordsInChannel(profiles)
mentions := GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["user"]; !ok || ids[0] != user1.Id {
@@ -442,7 +442,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user2.Id: user2}
mentions = GetMentionKeywordsInChannel(profiles)
mentions = GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 2 {
t.Fatal("should've returned two mention keyword")
} else if ids, ok := mentions["First"]; !ok || ids[0] != user2.Id {
@@ -460,7 +460,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user3.Id: user3}
mentions = GetMentionKeywordsInChannel(profiles)
mentions = GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["@channel"]; !ok || ids[0] != user3.Id {
@@ -482,7 +482,7 @@ func TestGetMentionKeywords(t *testing.T) {
}
profiles = map[string]*model.User{user4.Id: user4}
mentions = GetMentionKeywordsInChannel(profiles)
mentions = GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 6 {
t.Fatal("should've returned six mention keywords")
} else if ids, ok := mentions["user"]; !ok || ids[0] != user4.Id {
@@ -524,7 +524,7 @@ func TestGetMentionKeywords(t *testing.T) {
user3.Id: user3,
user4.Id: user4,
}
mentions = GetMentionKeywordsInChannel(profiles)
mentions = GetMentionKeywordsInChannel(profiles, true)
if len(mentions) != 6 {
t.Fatal("should've returned six mention keywords")
} else if ids, ok := mentions["user"]; !ok || len(ids) != 2 || (ids[0] != user1.Id && ids[1] != user1.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
@@ -534,12 +534,35 @@ func TestGetMentionKeywords(t *testing.T) {
} else if ids, ok := mentions["mention"]; !ok || len(ids) != 2 || (ids[0] != user1.Id && ids[1] != user1.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
t.Fatal("should've mentioned user1 and user4 with mention")
} else if ids, ok := mentions["First"]; !ok || len(ids) != 2 || (ids[0] != user2.Id && ids[1] != user2.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
t.Fatal("should've mentioned user2 and user4 with mention")
t.Fatal("should've mentioned user2 and user4 with First")
} else if ids, ok := mentions["@channel"]; !ok || len(ids) != 2 || (ids[0] != user3.Id && ids[1] != user3.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
t.Fatal("should've mentioned user3 and user4 with @channel")
} else if ids, ok := mentions["@all"]; !ok || len(ids) != 2 || (ids[0] != user3.Id && ids[1] != user3.Id) || (ids[0] != user4.Id && ids[1] != user4.Id) {
t.Fatal("should've mentioned user3 and user4 with @all")
}
// no special mentions
profiles = map[string]*model.User{
user1.Id: user1,
}
mentions = GetMentionKeywordsInChannel(profiles, false)
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["user"]; !ok || len(ids) != 1 || ids[0] != user1.Id {
t.Fatal("should've mentioned user1 with user")
} else if ids, ok := mentions["@user"]; !ok || len(ids) != 2 || ids[0] != user1.Id || ids[1] != user1.Id {
t.Fatal("should've mentioned user1 twice with @user")
} else if ids, ok := mentions["mention"]; !ok || len(ids) != 1 || ids[0] != user1.Id {
t.Fatal("should've mentioned user1 with mention")
} else if _, ok := mentions["First"]; ok {
t.Fatal("should not have mentioned user1 with First")
} else if _, ok := mentions["@channel"]; ok {
t.Fatal("should not have mentioned any user with @channel")
} else if _, ok := mentions["@all"]; ok {
t.Fatal("should not have mentioned any user with @all")
} else if _, ok := mentions["@here"]; ok {
t.Fatal("should not have mentioned any user with @here")
}
}
func TestDoesNotifyPropsAllowPushNotification(t *testing.T) {