mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
compose_validate: Simplify away extra stream_data lookups.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
48e836f01c
commit
db1f69e72f
@@ -1,5 +1,4 @@
|
|||||||
import $ from "jquery";
|
import $ from "jquery";
|
||||||
import assert from "minimalistic-assert";
|
|
||||||
|
|
||||||
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
|
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
|
||||||
import render_stream_does_not_exist_error from "../templates/compose_banner/stream_does_not_exist_error.hbs";
|
import render_stream_does_not_exist_error from "../templates/compose_banner/stream_does_not_exist_error.hbs";
|
||||||
@@ -7,6 +6,7 @@ import render_stream_does_not_exist_error from "../templates/compose_banner/stre
|
|||||||
import {$t} from "./i18n";
|
import {$t} from "./i18n";
|
||||||
import * as scroll_util from "./scroll_util";
|
import * as scroll_util from "./scroll_util";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
|
import type {StreamSubscription} from "./sub_store";
|
||||||
|
|
||||||
export let scroll_to_message_banner_message_id: number | null = null;
|
export let scroll_to_message_banner_message_id: number | null = null;
|
||||||
export function set_scroll_to_message_banner_message_id(val: number | null): void {
|
export function set_scroll_to_message_banner_message_id(val: number | null): void {
|
||||||
@@ -183,14 +183,11 @@ export function show_stream_does_not_exist_error(stream_name: string): void {
|
|||||||
$("#compose_select_recipient_widget").trigger("click");
|
$("#compose_select_recipient_widget").trigger("click");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function show_stream_not_subscribed_error(stream_name: string): void {
|
export function show_stream_not_subscribed_error(sub: StreamSubscription): void {
|
||||||
const $banner_container = $("#compose_banners");
|
const $banner_container = $("#compose_banners");
|
||||||
if ($(`#compose_banners .${CSS.escape(CLASSNAMES.user_not_subscribed)}`).length) {
|
if ($(`#compose_banners .${CSS.escape(CLASSNAMES.user_not_subscribed)}`).length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sub = stream_data.get_sub(stream_name);
|
|
||||||
// We expect this to be a does-not-exist error if it was undefined.
|
|
||||||
assert(sub !== undefined);
|
|
||||||
const new_row_html = render_compose_banner({
|
const new_row_html = render_compose_banner({
|
||||||
banner_type: ERROR,
|
banner_type: ERROR,
|
||||||
banner_text: $t({
|
banner_text: $t({
|
||||||
|
|||||||
@@ -540,11 +540,11 @@ export function validate_stream_message_mentions(opts: StreamWildcardOptions): b
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validate_stream_message_address_info(stream_name: string): boolean {
|
export function validate_stream_message_address_info(sub: StreamSubscription): boolean {
|
||||||
if (stream_data.is_subscribed_by_name(stream_name)) {
|
if (sub.subscribed) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
compose_banner.show_stream_not_subscribed_error(stream_name);
|
compose_banner.show_stream_not_subscribed_error(sub);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -598,7 +598,7 @@ function validate_stream_message(scheduling_message: boolean): boolean {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!validate_stream_message_address_info(sub.name) ||
|
!validate_stream_message_address_info(sub) ||
|
||||||
!validate_stream_message_mentions({
|
!validate_stream_message_mentions({
|
||||||
stream_id: sub.stream_id,
|
stream_id: sub.stream_id,
|
||||||
$banner_container,
|
$banner_container,
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ test_ui("validate_stream_message_address_info", ({mock_template}) => {
|
|||||||
subscribed: true,
|
subscribed: true,
|
||||||
};
|
};
|
||||||
stream_data.add_sub(party_sub);
|
stream_data.add_sub(party_sub);
|
||||||
assert.ok(compose_validate.validate_stream_message_address_info("social"));
|
assert.ok(compose_validate.validate_stream_message_address_info(party_sub));
|
||||||
|
|
||||||
party_sub.subscribed = false;
|
party_sub.subscribed = false;
|
||||||
stream_data.add_sub(party_sub);
|
stream_data.add_sub(party_sub);
|
||||||
@@ -101,14 +101,14 @@ test_ui("validate_stream_message_address_info", ({mock_template}) => {
|
|||||||
user_not_subscribed_rendered = true;
|
user_not_subscribed_rendered = true;
|
||||||
return html;
|
return html;
|
||||||
});
|
});
|
||||||
assert.ok(!compose_validate.validate_stream_message_address_info("social"));
|
assert.ok(!compose_validate.validate_stream_message_address_info(party_sub));
|
||||||
assert.ok(user_not_subscribed_rendered);
|
assert.ok(user_not_subscribed_rendered);
|
||||||
|
|
||||||
party_sub.name = "Frontend";
|
party_sub.name = "Frontend";
|
||||||
party_sub.stream_id = 102;
|
party_sub.stream_id = 102;
|
||||||
stream_data.add_sub(party_sub);
|
stream_data.add_sub(party_sub);
|
||||||
user_not_subscribed_rendered = false;
|
user_not_subscribed_rendered = false;
|
||||||
assert.ok(!compose_validate.validate_stream_message_address_info("Frontend"));
|
assert.ok(!compose_validate.validate_stream_message_address_info(party_sub));
|
||||||
assert.ok(user_not_subscribed_rendered);
|
assert.ok(user_not_subscribed_rendered);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user