compose: Show topic required error if topic is "(no topic)".

We already show the error if topic input is empty and it is
not allowed to send messages without topic in the organization,
and this commit also shows error when topic is "(no topic)".

The topic is set to "(no topic)" when someone sends a message
with empty topic input box and when it is allowed to send message
without topics in the organization.

This is not ideal behavior as we may want to treat "(no topic)"
differently from empty topic, but we can fix this in future and
this commit can be a short term fix.

Fixes #21344.
This commit is contained in:
Sahil Batra 2022-03-08 16:22:29 +05:30 committed by Tim Abbott
parent d693a6717c
commit cbac466658
2 changed files with 10 additions and 1 deletions

View File

@ -247,6 +247,13 @@ test_ui("validate", ({override, mock_template}) => {
$("#compose-error-msg").html(),
$t_html({defaultMessage: "Topics are required in this organization"}),
);
compose_state.topic("(no topic)");
assert.ok(!compose_validate.validate());
assert.equal(
$("#compose-error-msg").html(),
$t_html({defaultMessage: "Topics are required in this organization"}),
);
});
test_ui("get_invalid_recipient_emails", ({override_rewire}) => {

View File

@ -524,7 +524,9 @@ function validate_stream_message() {
if (page_params.realm_mandatory_topics) {
const topic = compose_state.topic();
if (topic === "") {
// TODO: We plan to migrate the empty topic to only using the
// `""` representation for i18n reasons, but have not yet done so.
if (topic === "" || topic === "(no topic)") {
compose_error.show(
$t_html({defaultMessage: "Topics are required in this organization"}),
$("#stream_message_recipient_topic"),