typeahead: Include wildcard mentions in typeahead for small streams.

We refactor the code checking if wildcard mentions are allowed by
renaming the pre-existing function `wildcard_mention_allowed` to
`wildcard_mention_allowed_in_large_stream`, adding a new function
`is_recipient_large_stream`, then redefining `wildcard_mention_allowed`
to combine these two functions.

Fixes: #27248.
This commit is contained in:
N-Shar-ma
2023-11-15 08:25:43 +05:30
committed by Tim Abbott
parent 27ffcc6576
commit bdba280c3d
2 changed files with 32 additions and 6 deletions

View File

@@ -341,7 +341,15 @@ function check_unsubscribed_stream_for_send(stream_name, autosubscribe) {
return result;
}
export function wildcard_mention_allowed() {
function is_recipient_large_stream() {
return (
compose_state.stream_id() &&
peer_data.get_subscriber_count(compose_state.stream_id()) >
wildcard_mention_large_stream_threshold
);
}
function wildcard_mention_allowed_in_large_stream() {
if (
page_params.realm_wildcard_mention_policy ===
settings_config.wildcard_mention_policy_values.by_everyone.code
@@ -385,6 +393,10 @@ export function wildcard_mention_allowed() {
return !page_params.is_guest;
}
export function wildcard_mention_allowed() {
return !is_recipient_large_stream() || wildcard_mention_allowed_in_large_stream();
}
export function set_wildcard_mention_large_stream_threshold(value) {
wildcard_mention_large_stream_threshold = value;
}
@@ -393,12 +405,13 @@ export function validate_stream_message_mentions(opts) {
const subscriber_count = peer_data.get_subscriber_count(opts.stream_id) || 0;
// If the user is attempting to do a wildcard mention in a large
// stream, check if they permission to do so.
// stream, check if they permission to do so. If yes, warn them
// if they haven't acknowledged the wildcard warning yet.
if (
opts.wildcard_mention !== null &&
subscriber_count > wildcard_mention_large_stream_threshold
) {
if (!wildcard_mention_allowed()) {
if (!wildcard_mention_allowed_in_large_stream()) {
compose_banner.show_error_message(
$t({
defaultMessage: