From 845e873c442c1ab111a0959830156b3b7fe550dc Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 14 Feb 2023 05:42:58 +0000 Subject: [PATCH] narrow_state: Add function to check if message feed is visible. We directly check if message feed is visible in the code instead of indirectly checking so via recent topics. This helps read the code clearly and would be helpful with the upcoming inbox view. --- static/js/compose_closed_ui.js | 9 +++------ static/js/hotkey.js | 11 ++++------- static/js/message_list_view.js | 3 +-- static/js/message_scroll.js | 2 +- static/js/narrow_state.js | 5 +++++ static/js/tippyjs.js | 3 +-- static/js/ui_init.js | 4 ++-- static/js/unread_ops.js | 4 ++-- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/static/js/compose_closed_ui.js b/static/js/compose_closed_ui.js index dcbd7207c5..1182a7695b 100644 --- a/static/js/compose_closed_ui.js +++ b/static/js/compose_closed_ui.js @@ -6,7 +6,6 @@ import * as message_lists from "./message_lists"; import * as message_store from "./message_store"; import * as narrow_state from "./narrow_state"; import * as people from "./people"; -import * as recent_topics_util from "./recent_topics_util"; export function get_recipient_label(message) { // TODO: This code path is bit of a type-checking disaster; we mix @@ -109,14 +108,12 @@ export function update_reply_recipient_label(message) { export function initialize() { // When the message selection changes, change the label on the Reply button. $(document).on("message_selected.zulip", () => { - if (recent_topics_util.is_visible()) { + if (narrow_state.is_message_feed_visible()) { // message_selected events can occur with recent topics // open due to "All messages" loading in the background, - // so we return without calling changing button state. - return; + // so we only update if message feed is visible. + update_reply_recipient_label(); } - - update_reply_recipient_label(); }); // Click handlers for buttons in the compose box. diff --git a/static/js/hotkey.js b/static/js/hotkey.js index af618a7a21..beda6929e5 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -27,6 +27,7 @@ import * as message_scroll from "./message_scroll"; import * as message_view_header from "./message_view_header"; import * as muted_topics_ui from "./muted_topics_ui"; import * as narrow from "./narrow"; +import * as narrow_state from "./narrow_state"; import * as navigate from "./navigate"; import * as overlays from "./overlays"; import {page_params} from "./page_params"; @@ -874,13 +875,9 @@ export function process_hotkey(e, hotkey) { return true; } - // We don't want hotkeys below this to work when recent topics is - // open. These involve hotkeys that can only be performed on a message. - if (recent_topics_util.is_visible()) { - return false; - } - - if (message_lists.current.empty()) { + // Hotkeys below this point are for the message feed, and so + // should only function if the message feed is visible and nonempty. + if (!narrow_state.is_message_feed_visible() || message_lists.current.empty()) { return false; } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index bb0ab004d1..87da22e383 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -27,7 +27,6 @@ import {page_params} from "./page_params"; import * as people from "./people"; import * as popovers from "./popovers"; import * as reactions from "./reactions"; -import * as recent_topics_util from "./recent_topics_util"; import * as rendered_markdown from "./rendered_markdown"; import * as rows from "./rows"; import * as stream_data from "./stream_data"; @@ -791,7 +790,7 @@ export class MessageListView { const restore_scroll_position = () => { if ( - !recent_topics_util.is_visible() && + narrow_state.is_message_feed_visible() && list === message_lists.current && orig_scrolltop_offset !== undefined ) { diff --git a/static/js/message_scroll.js b/static/js/message_scroll.js index fa1eaf080b..ad9643e90c 100644 --- a/static/js/message_scroll.js +++ b/static/js/message_scroll.js @@ -107,7 +107,7 @@ export function update_top_of_narrow_notices(msg_list) { message_lists.current !== message_lists.home ) { const filter = narrow_state.filter(); - if (filter === undefined && recent_topics_util.is_visible()) { + if (filter === undefined && !narrow_state.is_message_feed_visible()) { // user moved away from the narrow / filter to recent topics. return; } diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js index f791c104c4..f043db8bef 100644 --- a/static/js/narrow_state.js +++ b/static/js/narrow_state.js @@ -2,6 +2,7 @@ import * as blueslip from "./blueslip"; import {Filter} from "./filter"; import {page_params} from "./page_params"; import * as people from "./people"; +import * as recent_topics_util from "./recent_topics_util"; import * as stream_data from "./stream_data"; import * as unread from "./unread"; @@ -32,6 +33,10 @@ export function operators() { return current_filter.operators(); } +export function is_message_feed_visible() { + return !recent_topics_util.is_visible(); +} + export function update_email(user_id, new_email) { if (current_filter !== undefined) { current_filter.update_email(user_id, new_email); diff --git a/static/js/tippyjs.js b/static/js/tippyjs.js index 74b2466115..5d4f42593b 100644 --- a/static/js/tippyjs.js +++ b/static/js/tippyjs.js @@ -11,7 +11,6 @@ import * as message_lists from "./message_lists"; import * as narrow_state from "./narrow_state"; import * as popover_menus from "./popover_menus"; import * as reactions from "./reactions"; -import * as recent_topics_util from "./recent_topics_util"; import * as rows from "./rows"; import * as timerender from "./timerender"; import {parse_html} from "./ui_util"; @@ -251,7 +250,7 @@ export function initialize() { content() { const narrow_filter = narrow_state.filter(); let display_current_view; - if (!recent_topics_util.is_visible()) { + if (narrow_state.is_message_feed_visible()) { if (narrow_filter === undefined) { display_current_view = $t({defaultMessage: "Currently viewing all messages."}); } else if ( diff --git a/static/js/ui_init.js b/static/js/ui_init.js index e36603de9f..945f9ca0e8 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -52,6 +52,7 @@ import * as message_scroll from "./message_scroll"; import * as message_view_header from "./message_view_header"; import * as message_viewport from "./message_viewport"; import * as muted_users from "./muted_users"; +import * as narrow_state from "./narrow_state"; import * as navbar_alerts from "./navbar_alerts"; import * as navigate from "./navigate"; import * as notifications from "./notifications"; @@ -66,7 +67,6 @@ import * as realm_logo from "./realm_logo"; import * as realm_playground from "./realm_playground"; import * as realm_user_settings_defaults from "./realm_user_settings_defaults"; import * as recent_topics_ui from "./recent_topics_ui"; -import * as recent_topics_util from "./recent_topics_util"; import * as reload from "./reload"; import * as rendered_markdown from "./rendered_markdown"; import * as resize from "./resize"; @@ -259,7 +259,7 @@ export function initialize_kitchen_sink_stuff() { message_viewport.$message_pane.on("wheel", (e) => { const delta = e.originalEvent.deltaY; - if (!overlays.is_overlay_or_modal_open() && !recent_topics_util.is_visible()) { + if (!overlays.is_overlay_or_modal_open() && narrow_state.is_message_feed_visible()) { // In the message view, we use a throttled mousewheel handler. throttled_mousewheelhandler(e, delta); } diff --git a/static/js/unread_ops.js b/static/js/unread_ops.js index 29a0f0c354..38f6700ca6 100644 --- a/static/js/unread_ops.js +++ b/static/js/unread_ops.js @@ -9,10 +9,10 @@ import * as message_lists from "./message_lists"; import * as message_live_update from "./message_live_update"; import * as message_store from "./message_store"; import * as message_viewport from "./message_viewport"; +import * as narrow_state from "./narrow_state"; import * as notifications from "./notifications"; import * as people from "./people"; import * as recent_topics_ui from "./recent_topics_ui"; -import * as recent_topics_util from "./recent_topics_util"; import * as ui_report from "./ui_report"; import * as unread from "./unread"; import * as unread_ui from "./unread_ui"; @@ -369,7 +369,7 @@ export function notify_server_message_read(message, options) { } export function process_scrolled_to_bottom() { - if (recent_topics_util.is_visible()) { + if (!narrow_state.is_message_feed_visible()) { // First, verify the current message list is visible. return; }