refactor: Move append_compose_banner_to_banner_list to compose_banner.ts.

Before `scroll_util` typescript migration this function was present in `compose_validate`
but this function is more closely related to `compose_banner` module, hence moved this
function to `compose_banner`.
This commit is contained in:
Lalit
2023-04-27 11:07:38 +05:30
committed by Tim Abbott
parent c7b8f0658b
commit ae613c815e
4 changed files with 16 additions and 16 deletions

View File

@@ -3,6 +3,8 @@ import $ from "jquery";
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 * as scroll_util from "./scroll_util";
export let scroll_to_message_banner_message_id: number | null = null;
export function set_scroll_to_message_banner_message_id(val: number | null): void {
scroll_to_message_banner_message_id = val;
@@ -49,6 +51,10 @@ export const CLASSNAMES = {
user_not_subscribed: "user_not_subscribed",
};
export function append_compose_banner_to_banner_list(new_row: HTMLElement): void {
scroll_util.get_content_element($("#compose_banners")).append(new_row);
}
export function clear_message_sent_banners(include_unmute_banner = true): void {
for (const classname of Object.values(MESSAGE_SENT_CLASSNAMES)) {
$(`#compose_banners .${CSS.escape(classname)}`).remove();

View File

@@ -15,7 +15,6 @@ import {$t} from "./i18n";
import {page_params} from "./page_params";
import * as peer_data from "./peer_data";
import * as people from "./people";
import * as scroll_util from "./scroll_util";
import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data";
import * as stream_data from "./stream_data";
@@ -26,10 +25,6 @@ let wildcard_mention;
export let wildcard_mention_large_stream_threshold = 15;
export function append_compose_banner_to_banner_list(new_row) {
scroll_util.get_content_element($("#compose_banners")).append(new_row);
}
export function needs_subscribe_warning(user_id, stream_id) {
// This returns true if all of these conditions are met:
// * the user is valid
@@ -110,7 +105,7 @@ export function warn_if_private_stream_is_linked(linked_stream) {
classname: compose_banner.CLASSNAMES.private_stream_warning,
});
append_compose_banner_to_banner_list(new_row);
compose_banner.append_compose_banner_to_banner_list(new_row);
}
export function warn_if_mentioning_unsubscribed_user(mentioned) {
@@ -166,7 +161,7 @@ export function warn_if_mentioning_unsubscribed_user(mentioned) {
};
const new_row = render_not_subscribed_warning(context);
append_compose_banner_to_banner_list(new_row);
compose_banner.append_compose_banner_to_banner_list(new_row);
}
}
}
@@ -226,7 +221,7 @@ export function warn_if_topic_resolved(topic_changed) {
};
const new_row = render_compose_banner(context);
append_compose_banner_to_banner_list(new_row);
compose_banner.append_compose_banner_to_banner_list(new_row);
compose_state.set_recipient_viewed_topic_resolved_banner(true);
} else {
clear_topic_resolved_warning();
@@ -249,7 +244,7 @@ function show_wildcard_warnings(stream_id) {
// only show one error for any number of @all or @everyone mentions
if ($(`#compose_banners .${CSS.escape(classname)}`).length === 0) {
append_compose_banner_to_banner_list(wildcard_template);
compose_banner.append_compose_banner_to_banner_list(wildcard_template);
}
user_acknowledged_wildcard = false;
@@ -424,7 +419,7 @@ export function validation_error(error_type, stream_name) {
// closing the banner would be more confusing than helpful.
hide_close_button: true,
});
append_compose_banner_to_banner_list(new_row);
compose_banner.append_compose_banner_to_banner_list(new_row);
return false;
}
}

View File

@@ -7,7 +7,6 @@ import * as alert_words from "./alert_words";
import * as blueslip from "./blueslip";
import * as channel from "./channel";
import * as compose_banner from "./compose_banner";
import * as compose_validate from "./compose_validate";
import * as favicon from "./favicon";
import * as hash_util from "./hash_util";
import {$t} from "./i18n";
@@ -179,7 +178,7 @@ function notify_unmute(muted_narrow, stream_id, topic_name) {
}),
);
compose_banner.clear_unmute_topic_notifications();
compose_validate.append_compose_banner_to_banner_list($unmute_notification);
compose_banner.append_compose_banner_to_banner_list($unmute_notification);
}
export function notify_above_composebox(
@@ -201,7 +200,7 @@ export function notify_above_composebox(
// We pass in include_unmute_banner as false because we don't want to
// clear any unmute_banner associated with this same message.
compose_banner.clear_message_sent_banners(false);
compose_validate.append_compose_banner_to_banner_list($notification);
compose_banner.append_compose_banner_to_banner_list($notification);
}
if (window.electron_bridge !== undefined) {

View File

@@ -5,9 +5,9 @@ import $ from "jquery";
import render_upload_banner from "../templates/compose_banner/upload_banner.hbs";
import * as compose_actions from "./compose_actions";
import * as compose_banner from "./compose_banner";
import * as compose_state from "./compose_state";
import * as compose_ui from "./compose_ui";
import * as compose_validate from "./compose_validate";
import {csrf_token} from "./csrf";
import {$t} from "./i18n";
import {page_params} from "./page_params";
@@ -123,10 +123,10 @@ function add_upload_banner(config, banner_type, banner_text, file_id) {
banner_text,
file_id,
});
// TODO: Extend compose_validate.append_compose_banner_to_banner_list
// TODO: Extend compose_banner.append_compose_banner_to_banner_list
// to support the message edit container too.
if (config.mode === "compose") {
compose_validate.append_compose_banner_to_banner_list(new_banner);
compose_banner.append_compose_banner_to_banner_list(new_banner);
} else {
get_item("banner_container", config).append(new_banner);
}