filter: Remove incorrect check for `All messages` view.

All message view has `in-home` filter and is not empty.
If there are no terms provided, we set filter to display
all messages (including muted streams/topics).

We make it mandatory to provide terms to Filter.
This commit is contained in:
Aman Agrawal 2024-01-07 15:38:29 +00:00 committed by Tim Abbott
parent 5357b9814e
commit 272337f0f9
12 changed files with 43 additions and 38 deletions

View File

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

View File

@ -246,17 +246,12 @@ export class Filter {
_predicate?: (message: Message) => boolean;
_can_mark_messages_read?: boolean;
constructor(terms?: Term[]) {
if (terms === undefined) {
this._terms = [];
this._sub = undefined;
} else {
constructor(terms: Term[]) {
this._terms = this.fix_terms(terms);
if (this.has_operator("stream")) {
this._sub = stream_data.get_sub_by_name(this.operands("stream")[0]);
}
}
}
static canonicalize_operator(operator: string): string {
operator = operator.toLowerCase();
@ -761,11 +756,6 @@ export class Filter {
if (this.single_term_type_returns_all_messages_of_conversation()) {
return true;
}
const term_types = this.sorted_term_types();
if (_.isEqual(term_types, [])) {
// "All messages" view
return true;
}
return false;
}
@ -811,6 +801,11 @@ export class Filter {
return true;
}
if (_.isEqual(term_types, [])) {
// Empty filters means we are displaying all possible messages.
return true;
}
return false;
}

View File

@ -33,8 +33,11 @@ export function filter(): Filter | undefined {
export function search_terms(): Term[] {
if (current_filter === undefined) {
if (page_params.narrow !== undefined) {
return new Filter(page_params.narrow).terms();
}
return new Filter([]).terms();
}
return current_filter.terms();
}

View File

@ -40,7 +40,7 @@ function test_reply_label(expected_label) {
run_test("reply_label", () => {
// Mocking up a test message list
const filter = new Filter();
const filter = new Filter([]);
const list = new MessageList({
filter,
});

View File

@ -527,7 +527,7 @@ test("show_first_unread", () => {
filter = new Filter(terms);
assert.ok(!filter.allow_use_first_unread_when_narrowing());
filter = new Filter();
filter = new Filter([]);
assert.ok(filter.can_mark_messages_read());
assert.ok(filter.allow_use_first_unread_when_narrowing());
@ -987,7 +987,7 @@ test("predicate_edge_cases", () => {
let predicate;
// The code supports undefined as an operator to Filter, which results
// in a predicate that accepts any message.
predicate = new Filter().predicate();
predicate = new Filter([]).predicate();
assert.ok(predicate({}));
// Upstream code should prevent Filter.predicate from being called with

View File

@ -35,7 +35,7 @@ run_test("narrowing", () => {
// deactivating narrow
left_sidebar_navigation_area.handle_narrow_activated(new Filter());
left_sidebar_navigation_area.handle_narrow_activated(new Filter([]));
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
@ -53,7 +53,7 @@ run_test("narrowing", () => {
assert.ok(!$(".top_left_inbox").hasClass("active-filter"));
assert.ok($(".top_left_recent_view").hasClass("active-filter"));
left_sidebar_navigation_area.handle_narrow_activated(new Filter());
left_sidebar_navigation_area.handle_narrow_activated(new Filter([]));
left_sidebar_navigation_area.highlight_inbox_view();
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));

View File

@ -66,7 +66,7 @@ people.add_active_user(alice);
function make_home_msg_list() {
const table_name = "whatever";
const filter = new Filter();
const filter = new Filter([]);
const list = new message_list.MessageList({
table_name,

View File

@ -41,7 +41,7 @@ mock_esm("../src/message_list_view", {
const {Filter} = zrequire("filter");
run_test("basics", ({override}) => {
const filter = new Filter();
const filter = new Filter([]);
const list = new MessageList({
filter,
@ -136,7 +136,7 @@ run_test("basics", ({override}) => {
run_test("prev_next", () => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
assert.equal(list.prev(), undefined);
@ -177,7 +177,7 @@ run_test("prev_next", () => {
run_test("message_range", () => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
@ -193,7 +193,7 @@ run_test("message_range", () => {
run_test("nth_most_recent_id", () => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
list.append([{id: 10}, {id: 20}, {id: 30}]);
assert.equal(list.nth_most_recent_id(1), 30);
@ -204,7 +204,7 @@ run_test("nth_most_recent_id", () => {
run_test("change_message_id", () => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
list.data._add_to_hash([
{id: 10.5, content: "good job"},
@ -227,7 +227,7 @@ run_test("change_message_id", () => {
run_test("last_sent_by_me", () => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
const items = [
{
@ -252,7 +252,7 @@ run_test("last_sent_by_me", () => {
run_test("local_echo", () => {
let list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
list.append([
{id: 10},
@ -284,7 +284,7 @@ run_test("local_echo", () => {
assert.equal(list.closest_id(58), 60);
list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
list.append([
{id: 10},
@ -326,7 +326,7 @@ run_test("local_echo", () => {
run_test("bookend", ({override}) => {
const list = new MessageList({
filter: new Filter(),
filter: new Filter([]),
});
list.view.clear_trailing_bookend = noop;
@ -419,7 +419,7 @@ run_test("bookend", ({override}) => {
});
run_test("add_remove_rerender", () => {
const filter = new Filter();
const filter = new Filter([]);
const list = new MessageList({
filter,
});

View File

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

View File

@ -695,7 +695,7 @@ test("render_windows", () => {
const view = (function make_view() {
const table_name = "zfilt";
const filter = new Filter();
const filter = new Filter([]);
const list = new message_list.MessageList({
table_name,

View File

@ -4,6 +4,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const {page_params} = require("./lib/zpage_params");
const people = zrequire("people");
const {Filter} = zrequire("../src/filter");
@ -145,6 +146,12 @@ test("terms", () => {
narrow_state.reset_current_filter();
result = narrow_state.search_terms();
assert.equal(result.length, 0);
page_params.narrow = [{operator: "stream", operand: "Foo"}];
result = narrow_state.search_terms();
assert.equal(result.length, 1);
assert.equal(result[0].operator, "stream");
assert.equal(result[0].operand, "Foo");
});
test("excludes_muted_topics", () => {

View File

@ -83,7 +83,7 @@ function add_initialize_users() {
}
function init_message_list() {
const filter = new Filter();
const filter = new Filter([]);
const list = new MessageList({
filter,
});