From 303bbee2a2ae00c37f142b642902bbd0595a1fbf Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 17 Aug 2022 15:03:29 -0700 Subject: [PATCH] message_lists: Remove cases for table_name being undefined. The table_name property was only ever undefined for the special all_messages_list object. In 6f764ce4b3c05f6e1aa5cfceac3f13ddc423669e, we downgraded that object to only have a MessageListData; as a result, we now never construct a MessageList or MessageListView without `table_name` set correctly. --- frontend_tests/node_tests/compose_closed_ui.js | 13 +++++++++++-- frontend_tests/node_tests/dispatch.js | 14 ++++++++++++-- frontend_tests/node_tests/message_list.js | 11 +++++++++++ static/js/echo.js | 5 +---- static/js/message_list_view.js | 6 +----- static/js/message_live_update.js | 7 +------ 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/frontend_tests/node_tests/compose_closed_ui.js b/frontend_tests/node_tests/compose_closed_ui.js index e42865d14a..f373b2f027 100644 --- a/frontend_tests/node_tests/compose_closed_ui.js +++ b/frontend_tests/node_tests/compose_closed_ui.js @@ -10,11 +10,20 @@ const $ = require("../zjsunit/zjquery"); mock_esm("../../static/js/recent_topics_util", { is_visible: () => false, }); - +const noop = () => {}; // Mocking and stubbing things set_global("document", "document-stub"); const message_lists = mock_esm("../../static/js/message_lists"); - +function MessageListView() { + return { + maybe_rerender: noop, + append: noop, + prepend: noop, + }; +} +mock_esm("../../static/js/message_list_view", { + MessageListView, +}); // Code we're actually using/testing const compose_closed_ui = zrequire("compose_closed_ui"); const {Filter} = zrequire("filter"); diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 9beeb245cd..9aceb57b64 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -83,8 +83,18 @@ mock_esm("../../static/js/giphy"); const electron_bridge = set_global("electron_bridge", {}); -message_lists.current = {}; -message_lists.home = {}; +message_lists.current = { + rerender_view: noop, + data: { + get_messages_sent_by_user: () => [], + }, +}; +message_lists.home = { + rerender_view: noop, + data: { + get_messages_sent_by_user: () => [], + }, +}; message_lists.all_rendered_message_lists = () => [message_lists.home, message_lists.current]; // page_params is highly coupled to dispatching now diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 451f6670d3..afdabbf479 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -27,6 +27,17 @@ const narrow_state = mock_esm("../../static/js/narrow_state"); const stream_data = mock_esm("../../static/js/stream_data"); const {MessageList} = zrequire("message_list"); +function MessageListView() { + return { + maybe_rerender: noop, + append: noop, + prepend: noop, + clear_rendering_state: noop, + }; +} +mock_esm("../../static/js/message_list_view", { + MessageListView, +}); const {Filter} = zrequire("filter"); run_test("basics", ({override}) => { diff --git a/static/js/echo.js b/static/js/echo.js index 64ecfa27c6..71f064ad5c 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -366,10 +366,7 @@ export function update_message_lists({old_id, new_id}) { } for (const msg_list of message_lists.all_rendered_message_lists()) { msg_list.change_message_id(old_id, new_id); - - if (msg_list.view !== undefined) { - msg_list.view.change_message_id(old_id, new_id); - } + msg_list.view.change_message_id(old_id, new_id); } } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index c6a67b3727..b5ffd59ab6 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -700,7 +700,7 @@ export class MessageListView { // This function processes messages into chunks with separators between them, // and templates them to be inserted as table rows into the DOM. - if (messages.length === 0 || this.table_name === undefined) { + if (messages.length === 0) { return undefined; } @@ -1082,10 +1082,6 @@ export class MessageListView { } maybe_rerender() { - if (this.table_name === undefined) { - return false; - } - const selected_idx = this.list.selected_idx(); // We rerender under the following conditions: diff --git a/static/js/message_live_update.js b/static/js/message_live_update.js index 663a0d6186..f314ab5420 100644 --- a/static/js/message_live_update.js +++ b/static/js/message_live_update.js @@ -4,17 +4,12 @@ import * as people from "./people"; export function rerender_messages_view() { for (const list of message_lists.all_rendered_message_lists()) { - if (list.table_name !== undefined) { - list.rerender_view(); - } + list.rerender_view(); } } function rerender_messages_view_for_user(user_id) { for (const list of message_lists.all_rendered_message_lists()) { - if (list.table_name === undefined) { - continue; - } const messages = list.data.get_messages_sent_by_user(user_id); if (messages.length === 0) { continue;