PLT-4429 disabling at_all at_channel metions mentions when channel has more than 1k users (#4627)

* PLT-4429 disabling explicit mentions when channel has more than 1k users

* Fixing test case

* Adding setting to the admin console

* Fixing bad translation
Этот коммит содержится в:
Corey Hulen
2016-11-24 05:26:45 -08:00
коммит произвёл Harrison Healey
родитель 0f07a2d288
Коммит b212acf312
15 изменённых файлов: 211 добавлений и 45 удалений

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

@@ -475,7 +475,7 @@ func getMentionKeywordsInChannel(profiles map[string]*model.User) map[string][]s
}
// Add @channel and @all to keywords if user has them turned on
if profile.NotifyProps["channel"] == "true" {
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)
}
@@ -486,11 +486,13 @@ func getMentionKeywordsInChannel(profiles map[string]*model.User) map[string][]s
// 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 potencial mention users not in the channel and whether or not @here was mentioned.
func getExplicitMentions(message string, keywords map[string][]string) (map[string]bool, []string, bool) {
func getExplicitMentions(message string, keywords map[string][]string) (map[string]bool, []string, bool, bool, bool) {
mentioned := make(map[string]bool)
potentialOthersMentioned := make([]string, 0)
systemMentions := map[string]bool{"@here": true, "@channel": true, "@all": true}
hereMentioned := false
allMentioned := false
channelMentioned := false
addMentionedUsers := func(ids []string) {
for _, id := range ids {
@@ -505,6 +507,14 @@ func getExplicitMentions(message string, keywords map[string][]string) (map[stri
hereMentioned = true
}
if word == "@channel" {
channelMentioned = true
}
if word == "@all" {
allMentioned = true
}
// Non-case-sensitive check for regular keys
if ids, match := keywords[strings.ToLower(word)]; match {
addMentionedUsers(ids)
@@ -529,6 +539,14 @@ func getExplicitMentions(message string, keywords map[string][]string) (map[stri
hereMentioned = true
}
if splitWord == "@all" {
allMentioned = true
}
if splitWord == "@channel" {
channelMentioned = true
}
// Non-case-sensitive check for regular keys
if ids, match := keywords[strings.ToLower(splitWord)]; match {
addMentionedUsers(ids)
@@ -545,7 +563,7 @@ func getExplicitMentions(message string, keywords map[string][]string) (map[stri
}
}
return mentioned, potentialOthersMentioned, hereMentioned
return mentioned, potentialOthersMentioned, hereMentioned, channelMentioned, allMentioned
}
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel) []string {
@@ -569,6 +587,8 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
mentionedUserIds := make(map[string]bool)
allActivityPushUserIds := []string{}
hereNotification := false
channelNotification := false
allNotification := false
updateMentionChans := []store.StoreChannel{}
if channel.Type == model.CHANNEL_DIRECT {
@@ -584,7 +604,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
keywords := getMentionKeywordsInChannel(profileMap)
var potentialOtherMentions []string
mentionedUserIds, potentialOtherMentions, hereNotification = getExplicitMentions(post.Message, keywords)
mentionedUserIds, potentialOtherMentions, hereNotification, channelNotification, allNotification = getExplicitMentions(post.Message, keywords)
// get users that have comment thread mentions enabled
if len(post.RootId) > 0 {
@@ -652,7 +672,13 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
var status *model.Status
var err *model.AppError
if status, err = GetStatus(id); err != nil {
status = &model.Status{id, model.STATUS_OFFLINE, false, 0, ""}
status = &model.Status{
UserId: id,
Status: model.STATUS_OFFLINE,
Manual: false,
LastActivityAt: 0,
ActiveChannel: "",
}
}
if userAllowsEmails && status.Status != model.STATUS_ONLINE {
@@ -661,6 +687,46 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
}
}
// If the channel has more than 1K users then @here is disabled
if hereNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
hereNotification = false
SendEphemeralPost(
c.TeamId,
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_here", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
}
// If the channel has more than 1K users then @channel is disabled
if channelNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
SendEphemeralPost(
c.TeamId,
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_channel", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
}
// If the channel has more than 1K users then @all is disabled
if allNotification && int64(len(profileMap)) > *utils.Cfg.TeamSettings.MaxNotificationsPerChannel {
SendEphemeralPost(
c.TeamId,
post.UserId,
&model.Post{
ChannelId: post.ChannelId,
Message: utils.T("api.post.disabled_all", map[string]interface{}{"Users": *utils.Cfg.TeamSettings.MaxNotificationsPerChannel}),
CreateAt: post.CreateAt + 1,
},
)
}
if hereNotification {
if result := <-Srv.Store.Status().GetOnline(); result.Err != nil {
l4g.Warn(utils.T("api.post.notification.here.warn"), result.Err)