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 6f764ce4b3, 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.
This commit is contained in:
Tim Abbott 2022-08-17 15:03:29 -07:00
parent b8661b6633
commit 303bbee2a2
6 changed files with 37 additions and 19 deletions

View File

@ -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");

View File

@ -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

View File

@ -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}) => {

View File

@ -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);
}
}

View File

@ -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:

View File

@ -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;