Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose banner: Consolidate two functions that clear success banners.
evykassirer5f59ea0036c1
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex ab66eb88e6a..2e1d227e317 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -43,7 +43,7 @@ const transmit = mock_esm("../../static/js/transmit");const upload = mock_esm("../../static/js/upload");const compose_ui = zrequire("compose_ui");-const notifications = zrequire("notifications");+const compose_banner = zrequire("compose_banner");const compose_closed_ui = zrequire("compose_closed_ui");const compose_state = zrequire("compose_state");const compose = zrequire("compose");@@ -293,7 +293,7 @@ test_ui("send_message", ({override, override_rewire, mock_template}) => {test_ui("enter_with_preview_open", ({override, override_rewire}) => {mock_banners();- override_rewire(notifications, "clear_compose_notifications", () => {});+ override_rewire(compose_banner, "clear_message_sent_banners", () => {});override(reminder, "is_deferred_delivery", () => false);override(document, "to_$", () => $("document-stub"));let show_button_spinner_called = false;@@ -342,7 +342,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {test_ui("finish", ({override, override_rewire, mock_template}) => {mock_banners();- override_rewire(notifications, "clear_compose_notifications", () => {});+ override_rewire(compose_banner, "clear_message_sent_banners", () => {});override(reminder, "is_deferred_delivery", () => false);override(document, "to_$", () => $("document-stub"));let show_button_spinner_called = false;diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex 7b698ab69bc..8ee172ee9bc 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -13,6 +13,7 @@ mock_esm("../../static/js/resize", {const all_messages_data = mock_esm("../../static/js/all_messages_data");const channel = mock_esm("../../static/js/channel");const compose_actions = mock_esm("../../static/js/compose_actions");+const compose_banner = mock_esm("../../static/js/compose_banner");const compose_closed_ui = mock_esm("../../static/js/compose_closed_ui");const hashchange = mock_esm("../../static/js/hashchange");const message_fetch = mock_esm("../../static/js/message_fetch");@@ -71,13 +72,13 @@ function test_helper() {};}+ stub(compose_banner, "clear_message_sent_banners");stub(compose_actions, "on_narrow");stub(compose_closed_ui, "update_reply_recipient_label");stub(hashchange, "save_narrow");stub(message_scroll, "hide_indicators");stub(message_scroll, "show_loading_older");stub(message_scroll, "hide_top_of_narrow_notices");- stub(notifications, "clear_compose_notifications");stub(notifications, "redraw_title");stub(search, "update_button_visibility");stub(stream_list, "handle_narrow_activated");@@ -186,7 +187,7 @@ run_test("basics", () => {helper.assert_events([[message_scroll, "hide_top_of_narrow_notices"],[message_scroll, "hide_indicators"],- [notifications, "clear_compose_notifications"],+ [compose_banner, "clear_message_sent_banners"],[notifications, "redraw_title"],[unread_ops, "process_visible"],[hashchange, "save_narrow"],diff --git a/static/js/compose.js b/static/js/compose.jsindex 6ae42bb0296..62c0a67254f 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -19,7 +19,6 @@ import * as loading from "./loading";import * as markdown from "./markdown";import * as message_edit from "./message_edit";import * as narrow from "./narrow";-import * as notifications from "./notifications";import {page_params} from "./page_params";import * as people from "./people";import * as reminder from "./reminder";@@ -308,7 +307,7 @@ export function finish() {clear_preview_area();clear_invites();clear_private_stream_alert();- notifications.clear_compose_notifications();+ compose_banner.clear_message_sent_banners();const message_content = compose_state.message_content();diff --git a/static/js/compose_actions.js b/static/js/compose_actions.jsindex ed2c0400b83..07c8f8692c1 100644--- a/static/js/compose_actions.js+++ b/static/js/compose_actions.js@@ -19,7 +19,6 @@ import {$t} from "./i18n";import * as message_lists from "./message_lists";import * as message_viewport from "./message_viewport";import * as narrow_state from "./narrow_state";-import * as notifications from "./notifications";import {page_params} from "./page_params";import * as people from "./people";import * as recent_topics_ui from "./recent_topics_ui";@@ -292,7 +291,7 @@ export function start(msg_type, opts) {if (reload_state.is_in_progress()) {return;}- notifications.clear_compose_notifications();+ compose_banner.clear_message_sent_banners();expand_compose_box();opts = fill_in_opts_from_current_narrowed_view(msg_type, opts);@@ -384,7 +383,7 @@ export function cancel() {hide_box();$("#compose_close").hide();clear_box();- notifications.clear_compose_notifications();+ compose_banner.clear_message_sent_banners();compose.abort_xhr();compose.abort_video_callbacks(undefined);compose_state.set_message_type(false);diff --git a/static/js/compose_banner.ts b/static/js/compose_banner.tsindex 6431eabe645..3faf531dbd6 100644--- a/static/js/compose_banner.ts+++ b/static/js/compose_banner.ts@@ -3,6 +3,11 @@ 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";+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;+}+// banner typesexport const WARNING = "warning";export const ERROR = "error";@@ -42,6 +47,7 @@ export function clear_message_sent_banners(): void {for (const classname of Object.values(MESSAGE_SENT_CLASSNAMES)) {$(`#compose_banners .${classname}`).remove();}+ scroll_to_message_banner_message_id = null;}// TODO: Replace with compose_ui.hide_compose_spinner() when it is converted to ts.diff --git a/static/js/message_scroll.js b/static/js/message_scroll.jsindex 71bbddb40bd..2806b44bc5f 100644--- a/static/js/message_scroll.js+++ b/static/js/message_scroll.js@@ -1,6 +1,7 @@import $ from "jquery";import _ from "lodash";+import * as compose_banner from "./compose_banner";import * as floating_recipient_bar from "./floating_recipient_bar";import * as hash_util from "./hash_util";import * as loading from "./loading";@@ -9,7 +10,6 @@ import * as message_lists from "./message_lists";import * as message_viewport from "./message_viewport";import * as narrow_banner from "./narrow_banner";import * as narrow_state from "./narrow_state";-import * as notifications from "./notifications";import * as recent_topics_util from "./recent_topics_util";import * as unread from "./unread";import * as unread_ops from "./unread_ops";@@ -195,12 +195,12 @@ export function scroll_finished() {return;}- if (notifications.scroll_to_message_banner_message_id !== null) {+ if (compose_banner.scroll_to_message_banner_message_id !== null) {const $message_row = message_lists.current.get_row(- notifications.scroll_to_message_banner_message_id,+ compose_banner.scroll_to_message_banner_message_id,);if ($message_row.length > 0 && !message_viewport.is_message_below_viewport($message_row)) {- notifications.clear_compose_notifications();+ compose_banner.clear_message_sent_banners();}}diff --git a/static/js/narrow.js b/static/js/narrow.jsindex d643e221576..a282e538074 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -4,6 +4,7 @@ import {all_messages_data} from "./all_messages_data";import * as blueslip from "./blueslip";import * as channel from "./channel";import * as compose_actions from "./compose_actions";+import * as compose_banner from "./compose_banner";import * as compose_closed_ui from "./compose_closed_ui";import * as compose_fade from "./compose_fade";import * as compose_state from "./compose_state";@@ -417,7 +418,7 @@ export function activate(raw_operators, opts) {// most users aren't going to send a bunch of a out-of-narrow messages// and expect to visit a list of narrows, so let's get these out of the way.- notifications.clear_compose_notifications();+ compose_banner.clear_message_sent_banners();// Open tooltips are only interesting for current narrow,// so hide them when activating a new one.diff --git a/static/js/notifications.js b/static/js/notifications.jsindex 0f70bcf78f1..7bef0443021 100644--- a/static/js/notifications.js+++ b/static/js/notifications.js@@ -164,8 +164,6 @@ export function is_window_focused() {return window_focused;}-export let scroll_to_message_banner_message_id = null;-export function notify_above_composebox(banner_text,classname,@@ -182,7 +180,7 @@ export function notify_above_composebox(link_text,}),);- clear_compose_notifications();+ compose_banner.clear_message_sent_banners();$("#compose_banners").append($notification);}@@ -626,7 +624,7 @@ export function notify_local_mixes(messages, need_user_to_scroll) {link_msg_id,link_text,);- scroll_to_message_banner_message_id = link_msg_id;+ compose_banner.set_scroll_to_message_banner_message_id(link_msg_id);}// This is the HAPPY PATH--for most messages we do nothing@@ -684,11 +682,6 @@ export function notify_messages_outside_current_search(messages) {}}-export function clear_compose_notifications() {- compose_banner.clear_message_sent_banners();- scroll_to_message_banner_message_id = null;-}-export function reify_message_id(opts) {const old_id = opts.old_id;const new_id = opts.new_id;@@ -701,7 +694,7 @@ export function reify_message_id(opts) {if (message_id === old_id) {$elem.data("message-id", new_id);- scroll_to_message_banner_message_id = new_id;+ compose_banner.set_scroll_to_message_banner_message_id(new_id);}}}@@ -724,7 +717,7 @@ export function register_click_handlers() {const message_id = $(e.currentTarget).data("message-id");message_lists.current.select_id(message_id);navigate.scroll_to_selected();- clear_compose_notifications();+ compose_banner.clear_message_sent_banners();e.stopPropagation();e.preventDefault();},diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex ce2250efca8..6891ec66029 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -61,6 +61,7 @@ EXEMPT_FILES = make_set("static/js/click_handlers.js","static/js/compose.js","static/js/compose_actions.js",+ "static/js/compose_banner.ts","static/js/compose_closed_ui.js","static/js/compose_fade.js","static/js/compose_state.js",