refactor: Use is_broadcast flag for mention check.

I also clean up the noop tests here, which were
actually redundant (all three cases were short
circuiting on the "everyone" mention).
This commit is contained in:
Steve Howell 2020-01-14 17:39:10 +00:00 committed by Tim Abbott
parent e638361728
commit 34b21bc0ee
2 changed files with 8 additions and 7 deletions

View File

@ -1104,17 +1104,18 @@ run_test('warn_if_mentioning_unsubscribed_user', () => {
$('#compose_invite_users .compose_invite_user').length = 0; $('#compose_invite_users .compose_invite_user').length = 0;
function test_noop_case(msg_type, is_zephyr_mirror, mentioned_full_name) { function test_noop_case(is_private, is_zephyr_mirror, is_broadcast) {
const msg_type = is_private ? 'private' : 'stream';
compose_state.set_message_type(msg_type); compose_state.set_message_type(msg_type);
page_params.realm_is_zephyr_mirror_realm = is_zephyr_mirror; page_params.realm_is_zephyr_mirror_realm = is_zephyr_mirror;
mentioned.full_name = mentioned_full_name; mentioned.is_broadcast = is_broadcast;
compose.warn_if_mentioning_unsubscribed_user(mentioned); compose.warn_if_mentioning_unsubscribed_user(mentioned);
assert.equal($('#compose_invite_users').visible(), false); assert.equal($('#compose_invite_users').visible(), false);
} }
test_noop_case('private', true, 'everyone'); test_noop_case(true, false, false);
test_noop_case('stream', true, 'everyone'); test_noop_case(false, true, false);
test_noop_case('stream', false, 'everyone'); test_noop_case(false, false, true);
// Test mentioning a user that should gets a warning. // Test mentioning a user that should gets a warning.

View File

@ -849,8 +849,8 @@ exports.warn_if_mentioning_unsubscribed_user = function (mentioned) {
const email = mentioned.email; const email = mentioned.email;
if (mentioned.full_name === 'all' || mentioned.full_name === 'everyone' || mentioned.full_name === 'stream') { if (mentioned.is_broadcast) {
return; // don't check if @all or @everyone is subscribed to a stream return; // don't check if @all/@everyone/@stream
} }
if (exports.needs_subscribe_warning(email)) { if (exports.needs_subscribe_warning(email)) {