mirror of https://github.com/zulip/zulip.git
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:
parent
5357b9814e
commit
272337f0f9
|
@ -3,5 +3,5 @@ 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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
|
@ -246,15 +246,10 @@ export class Filter {
|
||||||
_predicate?: (message: Message) => boolean;
|
_predicate?: (message: Message) => boolean;
|
||||||
_can_mark_messages_read?: boolean;
|
_can_mark_messages_read?: boolean;
|
||||||
|
|
||||||
constructor(terms?: Term[]) {
|
constructor(terms: Term[]) {
|
||||||
if (terms === undefined) {
|
this._terms = this.fix_terms(terms);
|
||||||
this._terms = [];
|
if (this.has_operator("stream")) {
|
||||||
this._sub = undefined;
|
this._sub = stream_data.get_sub_by_name(this.operands("stream")[0]);
|
||||||
} else {
|
|
||||||
this._terms = this.fix_terms(terms);
|
|
||||||
if (this.has_operator("stream")) {
|
|
||||||
this._sub = stream_data.get_sub_by_name(this.operands("stream")[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,11 +756,6 @@ export class Filter {
|
||||||
if (this.single_term_type_returns_all_messages_of_conversation()) {
|
if (this.single_term_type_returns_all_messages_of_conversation()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const term_types = this.sorted_term_types();
|
|
||||||
if (_.isEqual(term_types, [])) {
|
|
||||||
// "All messages" view
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -811,6 +801,11 @@ export class Filter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_.isEqual(term_types, [])) {
|
||||||
|
// Empty filters means we are displaying all possible messages.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,10 @@ export function filter(): Filter | undefined {
|
||||||
|
|
||||||
export function search_terms(): Term[] {
|
export function search_terms(): Term[] {
|
||||||
if (current_filter === undefined) {
|
if (current_filter === undefined) {
|
||||||
return new Filter(page_params.narrow).terms();
|
if (page_params.narrow !== undefined) {
|
||||||
|
return new Filter(page_params.narrow).terms();
|
||||||
|
}
|
||||||
|
return new Filter([]).terms();
|
||||||
}
|
}
|
||||||
return current_filter.terms();
|
return current_filter.terms();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ function test_reply_label(expected_label) {
|
||||||
|
|
||||||
run_test("reply_label", () => {
|
run_test("reply_label", () => {
|
||||||
// Mocking up a test message list
|
// Mocking up a test message list
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter,
|
filter,
|
||||||
});
|
});
|
||||||
|
|
|
@ -527,7 +527,7 @@ test("show_first_unread", () => {
|
||||||
filter = new Filter(terms);
|
filter = new Filter(terms);
|
||||||
assert.ok(!filter.allow_use_first_unread_when_narrowing());
|
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.can_mark_messages_read());
|
||||||
assert.ok(filter.allow_use_first_unread_when_narrowing());
|
assert.ok(filter.allow_use_first_unread_when_narrowing());
|
||||||
|
|
||||||
|
@ -987,7 +987,7 @@ test("predicate_edge_cases", () => {
|
||||||
let predicate;
|
let predicate;
|
||||||
// The code supports undefined as an operator to Filter, which results
|
// The code supports undefined as an operator to Filter, which results
|
||||||
// in a predicate that accepts any message.
|
// in a predicate that accepts any message.
|
||||||
predicate = new Filter().predicate();
|
predicate = new Filter([]).predicate();
|
||||||
assert.ok(predicate({}));
|
assert.ok(predicate({}));
|
||||||
|
|
||||||
// Upstream code should prevent Filter.predicate from being called with
|
// Upstream code should prevent Filter.predicate from being called with
|
||||||
|
|
|
@ -35,7 +35,7 @@ run_test("narrowing", () => {
|
||||||
|
|
||||||
// deactivating narrow
|
// 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_all_messages").hasClass("active-filter"));
|
||||||
assert.ok(!$(".top_left_mentions").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_inbox").hasClass("active-filter"));
|
||||||
assert.ok($(".top_left_recent_view").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();
|
left_sidebar_navigation_area.highlight_inbox_view();
|
||||||
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
|
assert.ok(!$(".top_left_all_messages").hasClass("active-filter"));
|
||||||
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
assert.ok(!$(".top_left_mentions").hasClass("active-filter"));
|
||||||
|
|
|
@ -66,7 +66,7 @@ people.add_active_user(alice);
|
||||||
|
|
||||||
function make_home_msg_list() {
|
function make_home_msg_list() {
|
||||||
const table_name = "whatever";
|
const table_name = "whatever";
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
|
|
||||||
const list = new message_list.MessageList({
|
const list = new message_list.MessageList({
|
||||||
table_name,
|
table_name,
|
||||||
|
|
|
@ -41,7 +41,7 @@ mock_esm("../src/message_list_view", {
|
||||||
const {Filter} = zrequire("filter");
|
const {Filter} = zrequire("filter");
|
||||||
|
|
||||||
run_test("basics", ({override}) => {
|
run_test("basics", ({override}) => {
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
|
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter,
|
filter,
|
||||||
|
@ -136,7 +136,7 @@ run_test("basics", ({override}) => {
|
||||||
|
|
||||||
run_test("prev_next", () => {
|
run_test("prev_next", () => {
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter: new Filter(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(list.prev(), undefined);
|
assert.equal(list.prev(), undefined);
|
||||||
|
@ -177,7 +177,7 @@ run_test("prev_next", () => {
|
||||||
|
|
||||||
run_test("message_range", () => {
|
run_test("message_range", () => {
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter: new Filter(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
|
const messages = [{id: 30}, {id: 40}, {id: 50}, {id: 60}];
|
||||||
|
@ -193,7 +193,7 @@ 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(),
|
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);
|
||||||
|
@ -204,7 +204,7 @@ 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(),
|
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"},
|
||||||
|
@ -227,7 +227,7 @@ 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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
|
@ -252,7 +252,7 @@ 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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
list.append([
|
list.append([
|
||||||
{id: 10},
|
{id: 10},
|
||||||
|
@ -284,7 +284,7 @@ run_test("local_echo", () => {
|
||||||
assert.equal(list.closest_id(58), 60);
|
assert.equal(list.closest_id(58), 60);
|
||||||
|
|
||||||
list = new MessageList({
|
list = new MessageList({
|
||||||
filter: new Filter(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
list.append([
|
list.append([
|
||||||
{id: 10},
|
{id: 10},
|
||||||
|
@ -326,7 +326,7 @@ run_test("local_echo", () => {
|
||||||
|
|
||||||
run_test("bookend", ({override}) => {
|
run_test("bookend", ({override}) => {
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter: new Filter(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
list.view.clear_trailing_bookend = noop;
|
list.view.clear_trailing_bookend = noop;
|
||||||
|
@ -419,7 +419,7 @@ run_test("bookend", ({override}) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
run_test("add_remove_rerender", () => {
|
run_test("add_remove_rerender", () => {
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter,
|
filter,
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,7 +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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(mld.is_keyword_search(), false);
|
assert.equal(mld.is_keyword_search(), false);
|
||||||
|
@ -216,7 +216,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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
assert.deepEqual(mld._all_items, []);
|
assert.deepEqual(mld._all_items, []);
|
||||||
|
|
||||||
|
@ -251,7 +251,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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const orig_messages = [
|
const orig_messages = [
|
||||||
|
@ -299,7 +299,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(),
|
filter: new Filter([]),
|
||||||
});
|
});
|
||||||
assert.equal(mld.get("bogus-id"), undefined);
|
assert.equal(mld.get("bogus-id"), undefined);
|
||||||
|
|
||||||
|
|
|
@ -695,7 +695,7 @@ test("render_windows", () => {
|
||||||
|
|
||||||
const view = (function make_view() {
|
const view = (function make_view() {
|
||||||
const table_name = "zfilt";
|
const table_name = "zfilt";
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
|
|
||||||
const list = new message_list.MessageList({
|
const list = new message_list.MessageList({
|
||||||
table_name,
|
table_name,
|
||||||
|
|
|
@ -4,6 +4,7 @@ const {strict: assert} = require("assert");
|
||||||
|
|
||||||
const {zrequire} = require("./lib/namespace");
|
const {zrequire} = require("./lib/namespace");
|
||||||
const {run_test} = require("./lib/test");
|
const {run_test} = require("./lib/test");
|
||||||
|
const {page_params} = require("./lib/zpage_params");
|
||||||
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const {Filter} = zrequire("../src/filter");
|
const {Filter} = zrequire("../src/filter");
|
||||||
|
@ -145,6 +146,12 @@ test("terms", () => {
|
||||||
narrow_state.reset_current_filter();
|
narrow_state.reset_current_filter();
|
||||||
result = narrow_state.search_terms();
|
result = narrow_state.search_terms();
|
||||||
assert.equal(result.length, 0);
|
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", () => {
|
test("excludes_muted_topics", () => {
|
||||||
|
|
|
@ -83,7 +83,7 @@ function add_initialize_users() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_message_list() {
|
function init_message_list() {
|
||||||
const filter = new Filter();
|
const filter = new Filter([]);
|
||||||
const list = new MessageList({
|
const list = new MessageList({
|
||||||
filter,
|
filter,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue