mirror of https://github.com/zulip/zulip.git
filter: Make excludes_muted_topics a method of the `Filter` class.
This commit is contained in:
parent
c20340a5a6
commit
de0db7ad1a
|
@ -1208,4 +1208,17 @@ export class Filter {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
excludes_muted_topics(): boolean {
|
||||||
|
return (
|
||||||
|
// not narrowed to a topic
|
||||||
|
!(this.has_operator("stream") && this.has_operator("topic")) &&
|
||||||
|
// not narrowed to search
|
||||||
|
!this.is_keyword_search() &&
|
||||||
|
// not narrowed to dms
|
||||||
|
!(this.has_operator("dm") || this.has_operand("is", "dm")) &&
|
||||||
|
// not narrowed to starred messages
|
||||||
|
!this.has_operand("is", "starred")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,7 +410,7 @@ export function activate(raw_terms, opts) {
|
||||||
// From here on down, any calls to the narrow_state API will
|
// From here on down, any calls to the narrow_state API will
|
||||||
// reflect the upcoming narrow.
|
// reflect the upcoming narrow.
|
||||||
narrow_state.set_has_shown_message_list_view();
|
narrow_state.set_has_shown_message_list_view();
|
||||||
const excludes_muted_topics = narrow_state.excludes_muted_topics(filter);
|
const excludes_muted_topics = filter.excludes_muted_topics();
|
||||||
|
|
||||||
let msg_data = new MessageListData({
|
let msg_data = new MessageListData({
|
||||||
filter,
|
filter,
|
||||||
|
|
|
@ -378,15 +378,6 @@ export function narrowed_to_starred(current_filter: Filter | undefined = filter(
|
||||||
return current_filter.has_operand("is", "starred");
|
return current_filter.has_operand("is", "starred");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function excludes_muted_topics(filter: Filter): boolean {
|
|
||||||
return (
|
|
||||||
!narrowed_to_topic(filter) &&
|
|
||||||
!narrowed_to_search(filter) &&
|
|
||||||
!narrowed_to_pms(filter) &&
|
|
||||||
!narrowed_to_starred(filter)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function is_for_stream_id(stream_id: number, filter?: Filter): boolean {
|
export function is_for_stream_id(stream_id: number, filter?: Filter): boolean {
|
||||||
// This is not perfect, since we still track narrows by
|
// This is not perfect, since we still track narrows by
|
||||||
// name, not id, but at least the interface is good going
|
// name, not id, but at least the interface is good going
|
||||||
|
|
|
@ -33,9 +33,9 @@ function test_with(fixture) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const excludes_muted_topics = narrow_state.excludes_muted_topics();
|
const excludes_muted_topics = filter.excludes_muted_topics();
|
||||||
const msg_data = new MessageListData({
|
const msg_data = new MessageListData({
|
||||||
filter: narrow_state.filter(),
|
filter,
|
||||||
excludes_muted_topics,
|
excludes_muted_topics,
|
||||||
});
|
});
|
||||||
const id_info = {
|
const id_info = {
|
||||||
|
|
|
@ -17,11 +17,14 @@ function set_filter(raw_terms) {
|
||||||
operator: op[0],
|
operator: op[0],
|
||||||
operand: op[1],
|
operand: op[1],
|
||||||
}));
|
}));
|
||||||
|
const filter = new Filter(terms);
|
||||||
message_lists.set_current({
|
message_lists.set_current({
|
||||||
data: {
|
data: {
|
||||||
filter: new Filter(terms),
|
filter,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(label, f) {
|
function test(label, f) {
|
||||||
|
@ -160,26 +163,27 @@ test("terms", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("excludes_muted_topics", () => {
|
test("excludes_muted_topics", () => {
|
||||||
set_filter([["stream", "devel"]]);
|
let filter = set_filter([["stream", "devel"]]);
|
||||||
assert.ok(narrow_state.excludes_muted_topics());
|
assert.ok(filter.excludes_muted_topics());
|
||||||
|
|
||||||
message_lists.current = undefined; // not narrowed, basically
|
// All messages view.
|
||||||
assert.ok(narrow_state.excludes_muted_topics());
|
filter = set_filter([["in", "home"]]);
|
||||||
|
assert.ok(filter.excludes_muted_topics());
|
||||||
|
|
||||||
set_filter([
|
filter = set_filter([
|
||||||
["stream", "devel"],
|
["stream", "devel"],
|
||||||
["topic", "mac"],
|
["topic", "mac"],
|
||||||
]);
|
]);
|
||||||
assert.ok(!narrow_state.excludes_muted_topics());
|
assert.ok(!filter.excludes_muted_topics());
|
||||||
|
|
||||||
set_filter([["search", "whatever"]]);
|
filter = set_filter([["search", "whatever"]]);
|
||||||
assert.ok(!narrow_state.excludes_muted_topics());
|
assert.ok(!filter.excludes_muted_topics());
|
||||||
|
|
||||||
set_filter([["is", "private"]]);
|
filter = set_filter([["is", "private"]]);
|
||||||
assert.ok(!narrow_state.excludes_muted_topics());
|
assert.ok(!filter.excludes_muted_topics());
|
||||||
|
|
||||||
set_filter([["is", "starred"]]);
|
filter = set_filter([["is", "starred"]]);
|
||||||
assert.ok(!narrow_state.excludes_muted_topics());
|
assert.ok(!filter.excludes_muted_topics());
|
||||||
});
|
});
|
||||||
|
|
||||||
test("set_compose_defaults", () => {
|
test("set_compose_defaults", () => {
|
||||||
|
|
Loading…
Reference in New Issue