Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

mentions: Rename 'stream_wildcard_mention_allowed_in_large_stream'.

Prakhar Pratyush590d43f475b3
diff --git a/web/e2e-tests/mention.test.ts b/web/e2e-tests/mention.test.ts
index 7cd41b4d247..61492108d91 100644
--- a/web/e2e-tests/mention.test.ts
+++ b/web/e2e-tests/mention.test.ts
@@ -26,8 +26,8 @@ async function test_mention(page: Page): Promise<void> {
zulip_test.get_subscriber_count(zulip_test.get_sub("Verona").stream_id),
);
const threshold = await page.evaluate(() => {
- zulip_test.set_stream_wildcard_mention_large_stream_threshold(5);
- return zulip_test.stream_wildcard_mention_large_stream_threshold;
+ zulip_test.set_wildcard_mention_threshold(5);
+ return zulip_test.wildcard_mention_threshold;
});
assert.ok(stream_size > threshold);
await page.click("#compose-send-button");
diff --git a/web/src/compose_validate.js b/web/src/compose_validate.js
index a40cfcaa4be..110c5dbdf58 100644
--- a/web/src/compose_validate.js
+++ b/web/src/compose_validate.js
@@ -28,7 +28,7 @@ let upload_in_progress = false;
let message_too_long = false;
let recipient_disallowed = false;
-export let stream_wildcard_mention_large_stream_threshold = 15;
+export let wildcard_mention_threshold = 15;
export function set_upload_in_progress(status) {
upload_in_progress = status;
@@ -379,12 +379,11 @@ function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
function is_recipient_large_stream() {
return (
compose_state.stream_id() &&
- peer_data.get_subscriber_count(compose_state.stream_id()) >
- stream_wildcard_mention_large_stream_threshold
+ peer_data.get_subscriber_count(compose_state.stream_id()) > wildcard_mention_threshold
);
}
-function stream_wildcard_mention_allowed_in_large_stream() {
+function wildcard_mention_policy_authorizes_user() {
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_everyone.code
@@ -429,11 +428,11 @@ function stream_wildcard_mention_allowed_in_large_stream() {
}
export function wildcard_mention_allowed() {
- return !is_recipient_large_stream() || stream_wildcard_mention_allowed_in_large_stream();
+ return !is_recipient_large_stream() || wildcard_mention_policy_authorizes_user();
}
-export function set_stream_wildcard_mention_large_stream_threshold(value) {
- stream_wildcard_mention_large_stream_threshold = value;
+export function set_wildcard_mention_threshold(value) {
+ wildcard_mention_threshold = value;
}
export function validate_stream_message_mentions(opts) {
@@ -442,11 +441,8 @@ export function validate_stream_message_mentions(opts) {
// If the user is attempting to do a wildcard mention in a large
// stream, check if they permission to do so. If yes, warn them
// if they haven't acknowledged the wildcard warning yet.
- if (
- opts.stream_wildcard_mention !== null &&
- subscriber_count > stream_wildcard_mention_large_stream_threshold
- ) {
- if (!stream_wildcard_mention_allowed_in_large_stream()) {
+ if (opts.stream_wildcard_mention !== null && subscriber_count > wildcard_mention_threshold) {
+ if (!wildcard_mention_policy_authorizes_user()) {
const new_row = render_wildcard_mention_not_allowed_error({
banner_type: compose_banner.ERROR,
classname: compose_banner.CLASSNAMES.wildcards_not_allowed,
diff --git a/web/src/zulip_test.js b/web/src/zulip_test.js
index a73186a3000..efd264c8fce 100644
--- a/web/src/zulip_test.js
+++ b/web/src/zulip_test.js
@@ -2,10 +2,7 @@
// re-exports certain internal functions so they can be used by the
// Puppeteer tests. It should not be used in the code itself.
-export {
- set_stream_wildcard_mention_large_stream_threshold,
- stream_wildcard_mention_large_stream_threshold,
-} from "./compose_validate";
+export {set_wildcard_mention_threshold, wildcard_mention_threshold} from "./compose_validate";
export {private_message_recipient} from "./compose_state";
export {current as current_msg_list} from "./message_lists";
export {get_stream_id, get_sub, get_subscriber_count} from "./stream_data";
diff --git a/web/tests/compose_validate.test.js b/web/tests/compose_validate.test.js
index be04ba10fcf..563eaf4fec8 100644
--- a/web/tests/compose_validate.test.js
+++ b/web/tests/compose_validate.test.js
@@ -420,11 +420,7 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
assert.equal(data.subscriber_count, 16);
});
- override_rewire(
- compose_validate,
- "stream_wildcard_mention_allowed_in_large_stream",
- () => true,
- );
+ override_rewire(compose_validate, "wildcard_mention_policy_authorizes_user", () => true);
compose_state.message_content("Hey @**all**");
assert.ok(!compose_validate.validate());
assert.equal($("#compose-send-button").prop("disabled"), false);
@@ -436,11 +432,7 @@ test_ui("validate_stream_message", ({override_rewire, mock_template}) => {
assert.equal(data.stream_wildcard_mention, "all");
wildcards_not_allowed_rendered = true;
});
- override_rewire(
- compose_validate,
- "stream_wildcard_mention_allowed_in_large_stream",
- () => false,
- );
+ override_rewire(compose_validate, "wildcard_mention_policy_authorizes_user", () => false);
assert.ok(!compose_validate.validate());
assert.ok(wildcards_not_allowed_rendered);
});