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.

compose_validate: Remove `posting_policy_error_message` state tracking.

Aman Agrawal29acb7a93f9c
diff --git a/web/src/compose_validate.ts b/web/src/compose_validate.ts
index c20123bd2ed..17fa9b3545a 100644
--- a/web/src/compose_validate.ts
+++ b/web/src/compose_validate.ts
@@ -48,7 +48,6 @@ let message_too_long = false;
// we need to track when we are validating compose box.
let is_validating_compose_box = false;
let disabled_send_tooltip_message_html = "";
-let posting_policy_error_message = "";
export const NO_PERMISSION_TO_POST_IN_CHANNEL_ERROR_MESSAGE = $t({
defaultMessage: "You do not have permission to post in this channel.",
@@ -131,17 +130,6 @@ function set_message_too_long_for_edit(status: boolean, $container: JQuery): voi
$message_edit_save_container.toggleClass("disabled-message-edit-save", save_is_disabled);
}
-export function get_posting_policy_error_message(): string {
- // Contains errors which are shown as compose banner before user
- // clicks on the send button.
- // Ensure you are calling `validate` for the current compose state,
- // before calling this function.
- // We directly add the error banner instead of setting
- // `posting_policy_error_message`, when the banner contains special
- // context for the current compose state.
- return posting_policy_error_message;
-}
-
export function get_disabled_send_tooltip_html(): string {
return disabled_send_tooltip_message_html;
}
@@ -914,7 +902,6 @@ function validate_permission_to_post_messages_in_stream(sub: StreamSubscription)
if (is_validating_compose_box) {
disabled_send_tooltip_message_html = NO_PERMISSION_TO_POST_IN_CHANNEL_ERROR_MESSAGE;
- posting_policy_error_message = NO_PERMISSION_TO_POST_IN_CHANNEL_ERROR_MESSAGE;
}
return false;
}
@@ -1030,7 +1017,6 @@ export function validate_private_message(show_banner = true): boolean {
compose_banner.cannot_send_direct_message_error(direct_message_error_string);
if (is_validating_compose_box) {
disabled_send_tooltip_message_html = direct_message_error_string;
- posting_policy_error_message = direct_message_error_string;
}
return false;
}
@@ -1131,28 +1117,6 @@ export function check_overflow_text($container: JQuery): number {
return text.length;
}
-export let update_posting_policy_banner_post_validation = (): void => {
- const banner_text = get_posting_policy_error_message();
- if (banner_text === "") {
- compose_banner.clear_errors();
- return;
- }
-
- let banner_classname = compose_banner.CLASSNAMES.no_post_permissions;
- if (compose_state.selected_recipient_id === "direct") {
- banner_classname = compose_banner.CLASSNAMES.cannot_send_direct_message;
- compose_banner.cannot_send_direct_message_error(banner_text);
- } else {
- compose_banner.show_error_message(banner_text, banner_classname, $("#compose_banners"));
- }
-};
-
-export function rewire_update_posting_policy_banner_post_validation(
- value: typeof update_posting_policy_banner_post_validation,
-): void {
- update_posting_policy_banner_post_validation = value;
-}
-
export let validate_and_update_send_button_status = function (): void {
const is_valid = validate(false, false);
const $send_button = $("#compose-send-button");
@@ -1164,7 +1128,6 @@ export let validate_and_update_send_button_status = function (): void {
send_button_element._tippy.hide();
send_button_element._tippy.show();
}
- update_posting_policy_banner_post_validation();
};
export function rewire_validate_and_update_send_button_status(
@@ -1211,8 +1174,10 @@ function report_validation_error(
export let validate = (scheduling_message: boolean, show_banner = true): boolean => {
is_validating_compose_box = true;
- posting_policy_error_message = "";
disabled_send_tooltip_message_html = "";
+ // Clear previous banners from the previous compose state; the
+ // validation checks below will re-add any that are still relevant.
+ compose_banner.clear_errors();
const message_content = compose_state.message_content();
// The validation checks in this function are in a specific priority order. Don't
// change their order unless you want to change which priority they're shown in.
diff --git a/web/tests/compose_actions.test.cjs b/web/tests/compose_actions.test.cjs
index e089e51b7e8..4c08d501edf 100644
--- a/web/tests/compose_actions.test.cjs
+++ b/web/tests/compose_actions.test.cjs
@@ -114,7 +114,6 @@ const people = zrequire("people");
const compose_state = zrequire("compose_state");
const compose_actions = zrequire("compose_actions");
const compose_reply = zrequire("compose_reply");
-const compose_validate = zrequire("compose_validate");
const message_lists = zrequire("message_lists");
const stream_data = zrequire("stream_data");
const compose_recipient = zrequire("compose_recipient");
@@ -188,7 +187,6 @@ test("start", ({override, override_rewire, mock_template}) => {
$elem.set_find_results(".message-limit-indicator", $indicator);
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
- override_rewire(compose_validate, "update_posting_policy_banner_post_validation", noop);
override_rewire(compose_recipient, "update_recipient_row_attention_level", noop);
override_rewire(stream_data, "can_post_messages_in_stream", () => true);
override_rewire(stream_data, "can_create_new_topics_in_stream", () => true);
@@ -342,7 +340,6 @@ test("respond_to_message", ({override, override_rewire, mock_template}) => {
$elem.set_find_results(".message-limit-indicator", $indicator);
override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);
- override_rewire(compose_validate, "update_posting_policy_banner_post_validation", noop);
override_rewire(compose_recipient, "update_recipient_row_attention_level", noop);
override_private_message_recipient_ids({override});
mock_template("decorated_channel_name.hbs", false, () => "");
diff --git a/web/tests/upload.test.cjs b/web/tests/upload.test.cjs
index 1891b159d0d..799d4fd74ae 100644
--- a/web/tests/upload.test.cjs
+++ b/web/tests/upload.test.cjs
@@ -237,7 +237,6 @@ test("upload_files", async ({mock_template, override, override_rewire}) => {
return "<banner-stub>";
});
override_rewire(compose_validate, "validate", () => false);
- override_rewire(compose_validate, "update_posting_policy_banner_post_validation", noop);
await upload.upload_files(uppy, config, files);
assert.ok($("#compose-send-button").hasClass("disabled-message-send-controls"));
assert.ok(banner_shown);