stream_id: Replace empty string with undefined.

This commit also limits `stream_bar.decorate` to only
be able to be called for stream messages, since it's
an undefined string_id is no longer a sign that
you're dealing with a DM.
This commit is contained in:
evykassirer 2023-09-26 11:28:39 -07:00 committed by Tim Abbott
parent 07e6bcda7c
commit 77fc836edf
14 changed files with 28 additions and 28 deletions

View File

@ -218,7 +218,6 @@ EXEMPT_FILES = make_set(
"web/src/spectators.ts",
"web/src/spoilers.ts",
"web/src/starred_messages_ui.js",
"web/src/stream_bar.js",
"web/src/stream_color.js",
"web/src/stream_color_events.js",
"web/src/stream_create.js",

View File

@ -68,7 +68,7 @@ export function create_message_object() {
content: compose_state.message_content(),
sender_id: page_params.user_id,
queue_id: page_params.queue_id,
stream_id: "",
stream_id: undefined,
};
message.topic = "";

View File

@ -111,10 +111,12 @@ export function complete_starting_tasks(msg_type, opts) {
maybe_scroll_up_selected_message();
compose_fade.start_compose(msg_type);
if (msg_type === "stream") {
stream_bar.decorate(
opts.stream_id,
$("#stream_message_recipient_topic .message_header_stream"),
);
}
$(document).trigger(new $.Event("compose_started.zulip", opts));
compose_recipient.update_placeholder_text();
compose_recipient.update_narrow_to_recipient_visibility();
@ -148,7 +150,7 @@ export function maybe_scroll_up_selected_message() {
export function fill_in_opts_from_current_narrowed_view(msg_type, opts) {
return {
message_type: msg_type,
stream_id: "",
stream_id: undefined,
topic: "",
private_message_recipient: "",
trigger: "unknown",
@ -221,10 +223,12 @@ export function start(msg_type, opts) {
clear_box();
}
if (msg_type === "stream") {
const $stream_header_colorblock = $(
"#compose_select_recipient_widget_wrapper .stream_header_colorblock",
);
stream_bar.decorate(opts.stream_id, $stream_header_colorblock);
}
if (msg_type === "private") {
compose_state.set_compose_recipient_id(compose_state.DIRECT_MESSAGE_ID);

View File

@ -130,7 +130,7 @@ export function initialize() {
event.preventDefault();
const stream_id = compose_state.stream_id();
if (stream_id === "") {
if (stream_id === undefined) {
return;
}
const sub = stream_data.get_sub_by_id(stream_id);

View File

@ -85,7 +85,7 @@ export function stream_id() {
if (typeof stream_id === "number") {
return stream_id;
}
return "";
return undefined;
}
export function stream_name() {
@ -162,7 +162,7 @@ export function focus_in_empty_compose(consider_start_of_whitespace_message_empt
case "stream_message_recipient_topic":
return topic() === "";
case "compose_select_recipient_widget_wrapper":
return stream_id() === "";
return stream_id() === undefined;
}
return false;
@ -182,7 +182,7 @@ export function has_message_content() {
export function has_full_recipient() {
if (message_type === "stream") {
return stream_id() !== "" && topic() !== "";
return stream_id() !== undefined && topic() !== "";
}
return private_message_recipient() !== "";
}

View File

@ -79,7 +79,7 @@ function get_stream_id_for_textarea($textarea) {
return Number.parseInt(stream_id_str, 10);
}
return compose_state.stream_id() || undefined;
return compose_state.stream_id();
}
export function warn_if_private_stream_is_linked(linked_stream, $textarea) {
@ -480,7 +480,7 @@ export function validate_stream_message_address_info(stream_name) {
function validate_stream_message(scheduling_message) {
const stream_id = compose_state.stream_id();
const $banner_container = $("#compose_banners");
if (stream_id === "") {
if (stream_id === undefined) {
compose_banner.show_error_message(
$t({defaultMessage: "Please specify a stream."}),
compose_banner.CLASSNAMES.missing_stream,

View File

@ -26,7 +26,7 @@ function restore_draft(draft_id) {
const compose_args = {...drafts.restore_message(draft), draft_id};
if (compose_args.type === "stream") {
if (draft.stream_id !== "" && draft.topic !== "") {
if (draft.stream_id !== undefined && draft.topic !== "") {
narrow.activate(
[
{operator: "stream", operand: compose_args.stream_name},

View File

@ -112,7 +112,7 @@ export function set_up($input, pills, opts) {
return typeahead_helper.sort_recipients({
users,
query,
current_stream_id: "",
current_stream_id: undefined,
current_topic: undefined,
groups,
max_num_items: undefined,

View File

@ -5,9 +5,6 @@ import * as stream_data from "./stream_data";
// (In particular, if there's a color associated with it,
// have that color be reflected here too.)
export function decorate(stream_id, $element) {
if (stream_id === undefined) {
return;
}
const color = stream_data.get_color(stream_id);
$element.css("background-color", color);
}

View File

@ -198,7 +198,7 @@ test_ui("send_message", ({override, override_rewire, mock_template}) => {
sender_id: new_user.user_id,
queue_id: undefined,
resend: false,
stream_id: "",
stream_id: undefined,
topic: "",
to: `[${alice.user_id}]`,
reply_to: "alice@example.com",

View File

@ -127,7 +127,7 @@ test("start", ({override, override_rewire, mock_template}) => {
// Start stream message
compose_defaults = {
stream_id: "",
stream_id: undefined,
topic: "topic1",
};

View File

@ -187,7 +187,7 @@ run_test("replace_syntax", ({override}) => {
run_test("compute_placeholder_text", () => {
let opts = {
message_type: "stream",
stream_id: "",
stream_id: undefined,
topic: "",
private_message_recipient: "",
};
@ -216,7 +216,7 @@ run_test("compute_placeholder_text", () => {
// direct message narrows
opts = {
message_type: "private",
stream_id: "",
stream_id: undefined,
topic: "",
private_message_recipient: "",
};

View File

@ -139,7 +139,7 @@ test("basics", () => {
assert.ok(!stream_data.is_invite_only_by_stream_id(1000));
assert.equal(stream_data.get_color(social.stream_id), "red");
assert.equal(stream_data.get_color(""), "#c2c2c2");
assert.equal(stream_data.get_color(undefined), "#c2c2c2");
assert.equal(stream_data.get_name("denMARK"), "Denmark");
assert.equal(stream_data.get_name("unknown Stream"), "unknown Stream");

View File

@ -498,7 +498,7 @@ test("sort_recipients dup bots", () => {
const recipients = th.sort_recipients({
users: dup_objects,
query: "b",
current_stream_id: "",
current_stream_id: undefined,
current_topic: "",
});
const recipients_email = recipients.map((person) => person.email);