PLT-4762 Prevent turn off of (at)mentions (server) (#4714)

This commit is contained in:
enahum
2016-12-06 12:57:38 -03:00
committed by Christopher Speller
parent 08c2d28942
commit e57cba15ea
2 changed files with 29 additions and 8 deletions

View File

@@ -459,6 +459,9 @@ func getMentionKeywordsInChannel(profiles map[string]*model.User) map[string][]s
keywords := make(map[string][]string)
for id, profile := range profiles {
userMention := "@" + strings.ToLower(profile.Username)
keywords[userMention] = append(keywords[userMention], id)
if len(profile.NotifyProps["mention_keys"]) > 0 {
// Add all the user's mention keys
splitKeys := strings.Split(profile.NotifyProps["mention_keys"], ",")
@@ -698,7 +701,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_here", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
Message: c.T("api.post.disabled_here", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
@@ -711,7 +714,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_channel", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
Message: c.T("api.post.disabled_channel", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
@@ -724,7 +727,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_all", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
Message: c.T("api.post.disabled_all", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)

View File

@@ -937,8 +937,8 @@ func TestGetMentionKeywords(t *testing.T) {
profiles = map[string]*model.User{user2.Id: user2}
mentions = getMentionKeywordsInChannel(profiles)
if len(mentions) != 1 {
t.Fatal("should've returned one mention keyword")
if len(mentions) != 2 {
t.Fatal("should've returned two mention keyword")
} else if ids, ok := mentions["First"]; !ok || ids[0] != user2.Id {
t.Fatal("should've returned mention key of First")
}
@@ -955,8 +955,8 @@ func TestGetMentionKeywords(t *testing.T) {
profiles = map[string]*model.User{user3.Id: user3}
mentions = getMentionKeywordsInChannel(profiles)
if len(mentions) != 2 {
t.Fatal("should've returned two mention keywords")
if len(mentions) != 3 {
t.Fatal("should've returned three mention keywords")
} else if ids, ok := mentions["@channel"]; !ok || ids[0] != user3.Id {
t.Fatal("should've returned mention key of @channel")
} else if ids, ok := mentions["@all"]; !ok || ids[0] != user3.Id {
@@ -993,6 +993,24 @@ func TestGetMentionKeywords(t *testing.T) {
t.Fatal("should've returned mention key of @all")
}
dup_count := func(list []string) map[string]int {
duplicate_frequency := make(map[string]int)
for _, item := range list {
// check if the item/element exist in the duplicate_frequency map
_, exist := duplicate_frequency[item]
if exist {
duplicate_frequency[item] += 1 // increase counter by 1 if already in the map
} else {
duplicate_frequency[item] = 1 // else start counting from 1
}
}
return duplicate_frequency
}
// multiple users
profiles = map[string]*model.User{
user1.Id: user1,
@@ -1005,7 +1023,7 @@ func TestGetMentionKeywords(t *testing.T) {
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) {
t.Fatal("should've mentioned user1 and user4 with user")
} 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) {
} else if ids := dup_count(mentions["@user"]); len(ids) != 4 || (ids[user1.Id] != 2) || (ids[user4.Id] != 2) {
t.Fatal("should've mentioned user1 and user4 with @user")
} 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")