From 9e1b4dafc00393ff195571eeabafe3a7510cc941 Mon Sep 17 00:00:00 2001 From: Lalit Date: Wed, 10 May 2023 21:24:31 +0530 Subject: [PATCH] message_list_data: Remove dependency on `filter.js`. This commit removes dependency on `filter.js` by lifting the construction of `Filter` object up in `all_messages_data.js`. --- web/src/all_messages_data.js | 2 ++ web/src/message_list_data.js | 3 +-- web/tests/message_list.test.js | 32 +++++++++++++++++++++-------- web/tests/message_list_data.test.js | 4 ++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/web/src/all_messages_data.js b/web/src/all_messages_data.js index c94b96b42c..867cd66321 100644 --- a/web/src/all_messages_data.js +++ b/web/src/all_messages_data.js @@ -1,5 +1,7 @@ +import {Filter} from "./filter"; import {MessageListData} from "./message_list_data"; export const all_messages_data = new MessageListData({ excludes_muted_topics: false, + filter: new Filter(), }); diff --git a/web/src/message_list_data.js b/web/src/message_list_data.js index 77e4a58d3c..0122ce81f2 100644 --- a/web/src/message_list_data.js +++ b/web/src/message_list_data.js @@ -1,6 +1,5 @@ import * as blueslip from "./blueslip"; import {FetchStatus} from "./fetch_status"; -import {Filter} from "./filter"; import * as muted_users from "./muted_users"; import {page_params} from "./page_params"; import * as unread from "./unread"; @@ -15,7 +14,7 @@ export class MessageListData { // See also MessageList and MessageListView, which are important // to actually display a message list. - constructor({excludes_muted_topics, filter = new Filter()}) { + constructor({excludes_muted_topics, filter}) { // The Filter object defines which messages match the narrow, // and defines most of the configuration for the MessageListData. this.filter = filter; diff --git a/web/tests/message_list.test.js b/web/tests/message_list.test.js index a35a83a476..fbf7b925c8 100644 --- a/web/tests/message_list.test.js +++ b/web/tests/message_list.test.js @@ -135,7 +135,9 @@ run_test("basics", ({override}) => { }); run_test("prev_next", () => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); assert.equal(list.prev(), undefined); assert.equal(list.next(), undefined); @@ -174,7 +176,9 @@ run_test("prev_next", () => { }); run_test("message_range", () => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}]; list.append(messages, true); @@ -188,7 +192,9 @@ run_test("message_range", () => { }); run_test("nth_most_recent_id", () => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); list.append([{id: 10}, {id: 20}, {id: 30}]); assert.equal(list.nth_most_recent_id(1), 30); assert.equal(list.nth_most_recent_id(2), 20); @@ -197,7 +203,9 @@ run_test("nth_most_recent_id", () => { }); run_test("change_message_id", () => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); list.data._add_to_hash([ {id: 10.5, content: "good job"}, {id: 20.5, content: "ok!"}, @@ -218,7 +226,9 @@ run_test("change_message_id", () => { }); run_test("last_sent_by_me", () => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); const items = [ { id: 1, @@ -241,7 +251,9 @@ run_test("last_sent_by_me", () => { }); run_test("local_echo", () => { - let list = new MessageList({}); + let list = new MessageList({ + filter: new Filter(), + }); list.append([ {id: 10}, {id: 20}, @@ -271,7 +283,9 @@ run_test("local_echo", () => { assert.equal(list.closest_id(54), 50); assert.equal(list.closest_id(58), 60); - list = new MessageList({}); + list = new MessageList({ + filter: new Filter(), + }); list.append([ {id: 10}, {id: 20}, @@ -311,7 +325,9 @@ run_test("local_echo", () => { }); run_test("bookend", ({override}) => { - const list = new MessageList({}); + const list = new MessageList({ + filter: new Filter(), + }); list.view.clear_trailing_bookend = noop; list.narrowed = true; diff --git a/web/tests/message_list_data.test.js b/web/tests/message_list_data.test.js index 9ba123bfbd..91c5055c19 100644 --- a/web/tests/message_list_data.test.js +++ b/web/tests/message_list_data.test.js @@ -39,6 +39,7 @@ function assert_msg_ids(messages, msg_ids) { run_test("basics", () => { const mld = new MessageListData({ excludes_muted_topics: false, + filter: new Filter(), }); assert.equal(mld.is_search(), false); @@ -205,6 +206,7 @@ run_test("muting", () => { // and keep `_all_items` up-to-date. mld = new MessageListData({ excludes_muted_topics: true, + filter: new Filter(), }); assert.deepEqual(mld._all_items, []); @@ -239,6 +241,7 @@ run_test("muting", () => { // filtering the messages. mld = new MessageListData({ excludes_muted_topics: true, + filter: new Filter(), }); const orig_messages = [ @@ -286,6 +289,7 @@ run_test("muting", () => { run_test("errors", () => { const mld = new MessageListData({ excludes_muted_topics: false, + filter: new Filter(), }); assert.equal(mld.get("bogus-id"), undefined);