mirror of https://github.com/zulip/zulip.git
message_list: Make data required in the constructor.
This commit is contained in:
parent
28c3701677
commit
76a602842d
|
@ -4,8 +4,7 @@ import assert from "minimalistic-assert";
|
|||
|
||||
import * as blueslip from "./blueslip";
|
||||
import * as compose_tooltips from "./compose_tooltips";
|
||||
import type {Filter} from "./filter";
|
||||
import {MessageListData} from "./message_list_data";
|
||||
import type {MessageListData} from "./message_list_data";
|
||||
import * as message_list_tooltips from "./message_list_tooltips";
|
||||
import {MessageListView} from "./message_list_view";
|
||||
import type {Message} from "./message_store";
|
||||
|
@ -71,30 +70,14 @@ export class MessageList {
|
|||
last_message_historical?: boolean;
|
||||
should_trigger_message_selected_event?: boolean;
|
||||
|
||||
constructor(
|
||||
opts: (
|
||||
| {
|
||||
data: MessageListData;
|
||||
}
|
||||
| {
|
||||
data?: undefined;
|
||||
filter: Filter;
|
||||
}
|
||||
) & {excludes_muted_topics?: boolean; is_node_test?: boolean},
|
||||
) {
|
||||
constructor(opts: {
|
||||
data: MessageListData;
|
||||
excludes_muted_topics?: boolean;
|
||||
is_node_test?: boolean;
|
||||
}) {
|
||||
MessageList.id_counter += 1;
|
||||
this.id = MessageList.id_counter;
|
||||
if (opts.data) {
|
||||
this.data = opts.data;
|
||||
} else {
|
||||
const filter = opts.filter;
|
||||
|
||||
this.data = new MessageListData({
|
||||
excludes_muted_topics: opts.excludes_muted_topics ?? false,
|
||||
filter,
|
||||
});
|
||||
}
|
||||
|
||||
this.data = opts.data;
|
||||
this.data.set_rendered_message_list_id(this.id);
|
||||
|
||||
// TODO: This property should likely just be inlined into
|
||||
|
|
|
@ -26,6 +26,7 @@ const stream_data = zrequire("stream_data");
|
|||
const compose_closed_ui = zrequire("compose_closed_ui");
|
||||
const {Filter} = zrequire("filter");
|
||||
const {MessageList} = zrequire("message_list");
|
||||
const {MessageListData} = zrequire("message_list_data");
|
||||
|
||||
// Helper test function
|
||||
function test_reply_label(expected_label) {
|
||||
|
@ -43,7 +44,10 @@ run_test("reply_label", () => {
|
|||
// Mocking up a test message list
|
||||
const filter = new Filter([]);
|
||||
const list = new MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
});
|
||||
message_lists.current = list;
|
||||
const stream_one = {
|
||||
|
|
|
@ -27,6 +27,7 @@ const narrow_state = mock_esm("../src/narrow_state");
|
|||
const stream_data = mock_esm("../src/stream_data");
|
||||
|
||||
const {MessageList} = zrequire("message_list");
|
||||
const {MessageListData} = zrequire("message_list_data");
|
||||
function MessageListView() {
|
||||
return {
|
||||
maybe_rerender: noop,
|
||||
|
@ -45,7 +46,10 @@ run_test("basics", ({override}) => {
|
|||
const filter = new Filter([]);
|
||||
|
||||
const list = new MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
});
|
||||
|
||||
const messages = [
|
||||
|
@ -137,7 +141,10 @@ run_test("basics", ({override}) => {
|
|||
|
||||
run_test("prev_next", () => {
|
||||
const list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
|
||||
assert.equal(list.prev(), undefined);
|
||||
|
@ -178,7 +185,10 @@ run_test("prev_next", () => {
|
|||
|
||||
run_test("message_range", () => {
|
||||
const list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
|
||||
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
|
||||
|
@ -194,7 +204,10 @@ run_test("message_range", () => {
|
|||
|
||||
run_test("change_message_id", () => {
|
||||
const list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
list.data._add_to_hash([
|
||||
{id: 10.5, content: "good job"},
|
||||
|
@ -217,7 +230,10 @@ run_test("change_message_id", () => {
|
|||
|
||||
run_test("last_sent_by_me", () => {
|
||||
const list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
const items = [
|
||||
{
|
||||
|
@ -242,7 +258,10 @@ run_test("last_sent_by_me", () => {
|
|||
|
||||
run_test("local_echo", () => {
|
||||
let list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
list.append([
|
||||
{id: 10},
|
||||
|
@ -274,7 +293,10 @@ run_test("local_echo", () => {
|
|||
assert.equal(list.closest_id(58), 60);
|
||||
|
||||
list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
list.append([
|
||||
{id: 10},
|
||||
|
@ -316,7 +338,10 @@ run_test("local_echo", () => {
|
|||
|
||||
run_test("bookend", ({override}) => {
|
||||
const list = new MessageList({
|
||||
filter: new Filter([]),
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter: new Filter([]),
|
||||
}),
|
||||
});
|
||||
|
||||
list.view.clear_trailing_bookend = noop;
|
||||
|
@ -411,7 +436,10 @@ run_test("bookend", ({override}) => {
|
|||
run_test("add_remove_rerender", () => {
|
||||
const filter = new Filter([]);
|
||||
const list = new MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
});
|
||||
|
||||
const messages = [{id: 1}, {id: 2}, {id: 3}];
|
||||
|
|
|
@ -30,6 +30,7 @@ mock_esm("../src/people", {
|
|||
const {Filter} = zrequire("../src/filter");
|
||||
const {MessageListView} = zrequire("../src/message_list_view");
|
||||
const message_list = zrequire("message_list");
|
||||
const {MessageListData} = zrequire("message_list_data");
|
||||
const muted_users = zrequire("muted_users");
|
||||
|
||||
let next_timestamp = 1500000000;
|
||||
|
@ -473,7 +474,10 @@ test("merge_message_groups", ({mock_template}) => {
|
|||
const filter = new Filter([{operator: "stream", operand: "foo"}]);
|
||||
|
||||
const list = new message_list.MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
is_node_test: true,
|
||||
});
|
||||
|
||||
|
@ -734,7 +738,10 @@ test("render_windows", ({mock_template}) => {
|
|||
const filter = new Filter([]);
|
||||
|
||||
const list = new message_list.MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
is_node_test: true,
|
||||
});
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ const popover_menus_data = zrequire("popover_menus_data");
|
|||
const people = zrequire("people");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const user_groups = zrequire("user_groups");
|
||||
const {MessageListData} = zrequire("message_list_data");
|
||||
|
||||
const noop = function () {};
|
||||
|
||||
|
@ -104,7 +105,10 @@ function add_initialize_users() {
|
|||
function init_message_list() {
|
||||
const filter = new Filter([]);
|
||||
const list = new MessageList({
|
||||
filter,
|
||||
data: new MessageListData({
|
||||
excludes_muted_topics: false,
|
||||
filter,
|
||||
}),
|
||||
});
|
||||
|
||||
assert.equal(list.empty(), true);
|
||||
|
|
Loading…
Reference in New Issue