diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 6d56b6b9155..9f06d80b7f7 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -363,7 +363,7 @@ export default Ember.Component.extend({ const $e = $(e); var name = $e.data('name'); if (found.indexOf(name) === -1){ - this.sendAction('groupsMentioned', [{name: name, user_count: $e.data('mentionable-user-count')}]); + this.sendAction('groupsMentioned', [{name: name, user_count: $e.data('mentionable-user-count'), max_mentions: $e.data('max-mentions')}]); found.push(name); } }); diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 20b8736c6fa..0e6f9c6193a 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -378,11 +378,21 @@ export default Ember.Controller.extend({ groupsMentioned(groups) { if (!this.get('model.creatingPrivateMessage') && !this.get('model.topic.isPrivateMessage')) { groups.forEach(group => { - const body = I18n.t('composer.group_mentioned', { - group: "@" + group.name, - count: group.user_count, - group_link: Discourse.getURL(`/groups/${group.name}/members`) - }); + let body; + + if (group.max_mentions < group.user_count) { + body = I18n.t('composer.group_mentioned_limit', { + group: "@" + group.name, + max: group.max_mentions, + group_link: Discourse.getURL(`/groups/${group.name}/members`) + }); + } else { + body = I18n.t('composer.group_mentioned', { + group: "@" + group.name, + count: group.user_count, + group_link: Discourse.getURL(`/groups/${group.name}/members`) + }); + } this.appEvents.trigger('composer-messages:create', { extraClass: 'custom-body', diff --git a/app/assets/javascripts/discourse/lib/link-mentions.js.es6 b/app/assets/javascripts/discourse/lib/link-mentions.js.es6 index 688207c5b95..8aa802f80fc 100644 --- a/app/assets/javascripts/discourse/lib/link-mentions.js.es6 +++ b/app/assets/javascripts/discourse/lib/link-mentions.js.es6 @@ -2,13 +2,15 @@ import { ajax } from 'discourse/lib/ajax'; import { userPath } from 'discourse/lib/url'; import { formatUsername } from 'discourse/lib/utilities'; +let maxGroupMention; + function replaceSpan($e, username, opts) { let extra = ""; let extraClass = ""; if (opts && opts.group) { if (opts.mentionable) { - extra = `data-name='${username}' data-mentionable-user-count='${opts.mentionable.user_count}'`; + extra = `data-name='${username}' data-mentionable-user-count='${opts.mentionable.user_count}' data-max-mentions='${maxGroupMention}'`; extraClass = "notify"; } $e.replaceWith(`@${username}`); @@ -61,6 +63,7 @@ export function fetchUnseenMentions(usernames, topic_id) { r.valid_groups.forEach(vg => foundGroups[vg] = true); r.mentionable_groups.forEach(mg => mentionableGroups[mg.name] = mg); r.cannot_see.forEach(cs => cannotSee[cs] = true); + maxGroupMention = r.max_users_notified_per_group_mention; usernames.forEach(u => checked[u] = true); return r; }); diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3ce9e029bc9..c81c28dc849 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -248,7 +248,12 @@ class UsersController < ApplicationController Group.mentionable(current_user) .where(name: usernames) .pluck(:name, :user_count) - .map { |name, user_count| { name: name, user_count: user_count } } + .map do |name, user_count| + { + name: name, + user_count: user_count + } + end end usernames -= groups @@ -267,7 +272,13 @@ class UsersController < ApplicationController .where(username_lower: usernames) .pluck(:username_lower) - render json: { valid: result, valid_groups: groups, mentionable_groups: mentionable_groups, cannot_see: cannot_see } + render json: { + valid: result, + valid_groups: groups, + mentionable_groups: mentionable_groups, + cannot_see: cannot_see, + max_users_notified_per_group_mention: SiteSetting.max_users_notified_per_group_mention + } end def render_available_true diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a7fc27bf47a..eed1dd915dc 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1211,6 +1211,7 @@ en: similar_topics: "Your topic is similar to..." drafts_offline: "drafts offline" + group_mentioned_limit: "Warning! you mentioned {{group}}, however it has more members than the administrator configured limit of {{max}} users. Nobody will be notified. " group_mentioned: one: "By mentioning {{group}}, you are about to notify 1 person – are you sure?" other: "By mentioning {{group}}, you are about to notify {{count}} people – are you sure?"