filter: Make excludes_muted_topics a method of the `Filter` class.

This commit is contained in:
Aman Agrawal 2024-02-14 07:52:00 +00:00 committed by Tim Abbott
parent c20340a5a6
commit de0db7ad1a
5 changed files with 33 additions and 25 deletions

View File

@ -1208,4 +1208,17 @@ export class Filter {
}
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")
);
}
}

View File

@ -410,7 +410,7 @@ export function activate(raw_terms, opts) {
// From here on down, any calls to the narrow_state API will
// reflect the upcoming narrow.
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({
filter,

View File

@ -378,15 +378,6 @@ export function narrowed_to_starred(current_filter: Filter | undefined = filter(
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 {
// This is not perfect, since we still track narrows by
// name, not id, but at least the interface is good going

View File

@ -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({
filter: narrow_state.filter(),
filter,
excludes_muted_topics,
});
const id_info = {

View File

@ -17,11 +17,14 @@ function set_filter(raw_terms) {
operator: op[0],
operand: op[1],
}));
const filter = new Filter(terms);
message_lists.set_current({
data: {
filter: new Filter(terms),
filter,
},
});
return filter;
}
function test(label, f) {
@ -160,26 +163,27 @@ test("terms", () => {
});
test("excludes_muted_topics", () => {
set_filter([["stream", "devel"]]);
assert.ok(narrow_state.excludes_muted_topics());
let filter = set_filter([["stream", "devel"]]);
assert.ok(filter.excludes_muted_topics());
message_lists.current = undefined; // not narrowed, basically
assert.ok(narrow_state.excludes_muted_topics());
// All messages view.
filter = set_filter([["in", "home"]]);
assert.ok(filter.excludes_muted_topics());
set_filter([
filter = set_filter([
["stream", "devel"],
["topic", "mac"],
]);
assert.ok(!narrow_state.excludes_muted_topics());
assert.ok(!filter.excludes_muted_topics());
set_filter([["search", "whatever"]]);
assert.ok(!narrow_state.excludes_muted_topics());
filter = set_filter([["search", "whatever"]]);
assert.ok(!filter.excludes_muted_topics());
set_filter([["is", "private"]]);
assert.ok(!narrow_state.excludes_muted_topics());
filter = set_filter([["is", "private"]]);
assert.ok(!filter.excludes_muted_topics());
set_filter([["is", "starred"]]);
assert.ok(!narrow_state.excludes_muted_topics());
filter = set_filter([["is", "starred"]]);
assert.ok(!filter.excludes_muted_topics());
});
test("set_compose_defaults", () => {