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`.
This commit is contained in:
Lalit 2023-05-10 21:24:31 +05:30 committed by Tim Abbott
parent fc22b86eb6
commit 9e1b4dafc0
4 changed files with 31 additions and 10 deletions

View File

@ -1,5 +1,7 @@
import {Filter} from "./filter";
import {MessageListData} from "./message_list_data"; import {MessageListData} from "./message_list_data";
export const all_messages_data = new MessageListData({ export const all_messages_data = new MessageListData({
excludes_muted_topics: false, excludes_muted_topics: false,
filter: new Filter(),
}); });

View File

@ -1,6 +1,5 @@
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import {FetchStatus} from "./fetch_status"; import {FetchStatus} from "./fetch_status";
import {Filter} from "./filter";
import * as muted_users from "./muted_users"; import * as muted_users from "./muted_users";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as unread from "./unread"; import * as unread from "./unread";
@ -15,7 +14,7 @@ export class MessageListData {
// See also MessageList and MessageListView, which are important // See also MessageList and MessageListView, which are important
// to actually display a message list. // 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, // The Filter object defines which messages match the narrow,
// and defines most of the configuration for the MessageListData. // and defines most of the configuration for the MessageListData.
this.filter = filter; this.filter = filter;

View File

@ -135,7 +135,9 @@ run_test("basics", ({override}) => {
}); });
run_test("prev_next", () => { run_test("prev_next", () => {
const list = new MessageList({}); const list = new MessageList({
filter: new Filter(),
});
assert.equal(list.prev(), undefined); assert.equal(list.prev(), undefined);
assert.equal(list.next(), undefined); assert.equal(list.next(), undefined);
@ -174,7 +176,9 @@ run_test("prev_next", () => {
}); });
run_test("message_range", () => { 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}]; const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
list.append(messages, true); list.append(messages, true);
@ -188,7 +192,9 @@ run_test("message_range", () => {
}); });
run_test("nth_most_recent_id", () => { 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}]); list.append([{id: 10}, {id: 20}, {id: 30}]);
assert.equal(list.nth_most_recent_id(1), 30); assert.equal(list.nth_most_recent_id(1), 30);
assert.equal(list.nth_most_recent_id(2), 20); assert.equal(list.nth_most_recent_id(2), 20);
@ -197,7 +203,9 @@ run_test("nth_most_recent_id", () => {
}); });
run_test("change_message_id", () => { run_test("change_message_id", () => {
const list = new MessageList({}); const list = new MessageList({
filter: new Filter(),
});
list.data._add_to_hash([ list.data._add_to_hash([
{id: 10.5, content: "good job"}, {id: 10.5, content: "good job"},
{id: 20.5, content: "ok!"}, {id: 20.5, content: "ok!"},
@ -218,7 +226,9 @@ run_test("change_message_id", () => {
}); });
run_test("last_sent_by_me", () => { run_test("last_sent_by_me", () => {
const list = new MessageList({}); const list = new MessageList({
filter: new Filter(),
});
const items = [ const items = [
{ {
id: 1, id: 1,
@ -241,7 +251,9 @@ run_test("last_sent_by_me", () => {
}); });
run_test("local_echo", () => { run_test("local_echo", () => {
let list = new MessageList({}); let list = new MessageList({
filter: new Filter(),
});
list.append([ list.append([
{id: 10}, {id: 10},
{id: 20}, {id: 20},
@ -271,7 +283,9 @@ run_test("local_echo", () => {
assert.equal(list.closest_id(54), 50); assert.equal(list.closest_id(54), 50);
assert.equal(list.closest_id(58), 60); assert.equal(list.closest_id(58), 60);
list = new MessageList({}); list = new MessageList({
filter: new Filter(),
});
list.append([ list.append([
{id: 10}, {id: 10},
{id: 20}, {id: 20},
@ -311,7 +325,9 @@ run_test("local_echo", () => {
}); });
run_test("bookend", ({override}) => { run_test("bookend", ({override}) => {
const list = new MessageList({}); const list = new MessageList({
filter: new Filter(),
});
list.view.clear_trailing_bookend = noop; list.view.clear_trailing_bookend = noop;
list.narrowed = true; list.narrowed = true;

View File

@ -39,6 +39,7 @@ function assert_msg_ids(messages, msg_ids) {
run_test("basics", () => { run_test("basics", () => {
const mld = new MessageListData({ const mld = new MessageListData({
excludes_muted_topics: false, excludes_muted_topics: false,
filter: new Filter(),
}); });
assert.equal(mld.is_search(), false); assert.equal(mld.is_search(), false);
@ -205,6 +206,7 @@ run_test("muting", () => {
// and keep `_all_items` up-to-date. // and keep `_all_items` up-to-date.
mld = new MessageListData({ mld = new MessageListData({
excludes_muted_topics: true, excludes_muted_topics: true,
filter: new Filter(),
}); });
assert.deepEqual(mld._all_items, []); assert.deepEqual(mld._all_items, []);
@ -239,6 +241,7 @@ run_test("muting", () => {
// filtering the messages. // filtering the messages.
mld = new MessageListData({ mld = new MessageListData({
excludes_muted_topics: true, excludes_muted_topics: true,
filter: new Filter(),
}); });
const orig_messages = [ const orig_messages = [
@ -286,6 +289,7 @@ run_test("muting", () => {
run_test("errors", () => { run_test("errors", () => {
const mld = new MessageListData({ const mld = new MessageListData({
excludes_muted_topics: false, excludes_muted_topics: false,
filter: new Filter(),
}); });
assert.equal(mld.get("bogus-id"), undefined); assert.equal(mld.get("bogus-id"), undefined);