From 0f084587e01fc3e72b9083e26bc875231f66ee5e Mon Sep 17 00:00:00 2001 From: Karl Stolley Date: Wed, 4 Oct 2023 11:36:15 -0500 Subject: [PATCH] compose: Make stronger, more readable button-update logic. --- web/src/compose_closed_ui.js | 4 ++-- web/src/narrow.js | 4 +++- web/src/recent_view_ui.js | 2 +- web/tests/compose.test.js | 2 +- web/tests/narrow_activate.test.js | 4 ++-- web/tests/recent_view.test.js | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/web/src/compose_closed_ui.js b/web/src/compose_closed_ui.js index 606fa00cf1..f30cea4013 100644 --- a/web/src/compose_closed_ui.js +++ b/web/src/compose_closed_ui.js @@ -119,7 +119,7 @@ export function update_buttons_for_private() { update_buttons(text_stream, disable_reply); } -export function update_buttons_for_stream() { +export function update_buttons_for_stream_views() { const text_stream = $t({defaultMessage: "Start new conversation"}); $("#new_conversation_button").attr( "data-tooltip-template-id", @@ -128,7 +128,7 @@ export function update_buttons_for_stream() { update_buttons(text_stream); } -export function update_buttons_for_recent_view() { +export function update_buttons_for_non_stream_views() { const text_stream = $t({defaultMessage: "Start new conversation"}); $("#new_conversation_button").attr( "data-tooltip-template-id", diff --git a/web/src/narrow.js b/web/src/narrow.js index 06b0cd7abf..581870b8c0 100644 --- a/web/src/narrow.js +++ b/web/src/narrow.js @@ -926,8 +926,10 @@ function handle_post_view_change(msg_list) { if (filter.contains_only_private_messages()) { compose_closed_ui.update_buttons_for_private(); + } else if (filter.is_conversation_view() || filter.includes_full_stream_history()) { + compose_closed_ui.update_buttons_for_stream_views(); } else { - compose_closed_ui.update_buttons_for_stream(); + compose_closed_ui.update_buttons_for_non_stream_views(); } compose_closed_ui.update_reply_recipient_label(); diff --git a/web/src/recent_view_ui.js b/web/src/recent_view_ui.js index 734fe09ea1..8894624c37 100644 --- a/web/src/recent_view_ui.js +++ b/web/src/recent_view_ui.js @@ -918,7 +918,7 @@ export function show() { // We want to show `new stream message` instead of // `new topic`, which we are already doing in this // function. So, we reuse it here. - update_compose: compose_closed_ui.update_buttons_for_recent_view, + update_compose: compose_closed_ui.update_buttons_for_non_stream_views, is_recent_view: true, is_visible, set_visible, diff --git a/web/tests/compose.test.js b/web/tests/compose.test.js index 966914d4b1..93d8526343 100644 --- a/web/tests/compose.test.js +++ b/web/tests/compose.test.js @@ -784,7 +784,7 @@ test_ui("narrow_button_titles", ({override}) => { $t({defaultMessage: "New direct message"}), ); - compose_closed_ui.update_buttons_for_stream(); + compose_closed_ui.update_buttons_for_stream_views(); assert.equal( $("#new_conversation_button").text(), $t({defaultMessage: "Start new conversation"}), diff --git a/web/tests/narrow_activate.test.js b/web/tests/narrow_activate.test.js index 47a91fb083..adb9697789 100644 --- a/web/tests/narrow_activate.test.js +++ b/web/tests/narrow_activate.test.js @@ -95,7 +95,7 @@ function test_helper({override}) { stub(left_sidebar_navigation_area, "handle_narrow_activated"); stub(typing_events, "render_notifications_for_narrow"); stub(unread_ops, "process_visible"); - stub(compose_closed_ui, "update_buttons_for_stream"); + stub(compose_closed_ui, "update_buttons_for_stream_views"); stub(compose_closed_ui, "update_buttons_for_private"); // We don't test the css calls; we just skip over them. $("#mark_read_on_scroll_state_banner").toggleClass = () => {}; @@ -194,7 +194,7 @@ run_test("basics", ({override}) => { [message_viewport, "stop_auto_scrolling"], [browser_history, "set_hash"], [typing_events, "render_notifications_for_narrow"], - [compose_closed_ui, "update_buttons_for_stream"], + [compose_closed_ui, "update_buttons_for_stream_views"], [compose_closed_ui, "update_reply_recipient_label"], [message_view_header, "render_title_area"], [narrow_title, "update_narrow_title"], diff --git a/web/tests/recent_view.test.js b/web/tests/recent_view.test.js index 483b5f2da8..19b6b14be9 100644 --- a/web/tests/recent_view.test.js +++ b/web/tests/recent_view.test.js @@ -89,7 +89,7 @@ const ListWidget = mock_esm("../src/list_widget", { mock_esm("../src/compose_closed_ui", { set_standard_text_for_reply_button: noop, - update_buttons_for_recent_view: noop, + update_buttons_for_non_stream_views: noop, }); mock_esm("../src/hash_util", { by_stream_url: test_url,