message_events: Extract function to check if filter has term type.

Not added to `Filter` library since this function is a bit
localized to message_events us case in the sense that it
checks for existence of `not-` prefix of the term type too.
This commit is contained in:
Aman Agrawal 2024-11-01 23:38:23 +05:30 committed by Tim Abbott
parent 662f364283
commit 517fabd123
1 changed files with 9 additions and 5 deletions

View File

@ -39,17 +39,21 @@ import * as unread from "./unread";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
import * as util from "./util"; import * as util from "./util";
function filter_has_term_type(filter, term_type) {
return (
filter !== undefined &&
(filter.sorted_term_types().includes(term_type) ||
filter.sorted_term_types().includes(`not-${term_type}`))
);
}
export function update_current_view_for_topic_visibility() { export function update_current_view_for_topic_visibility() {
// If we have rendered message list / cached data based on topic // If we have rendered message list / cached data based on topic
// visibility policy, we need to rerender it to reflect the changes. It // visibility policy, we need to rerender it to reflect the changes. It
// is easier to just load the narrow from scratch, instead of asking server // is easier to just load the narrow from scratch, instead of asking server
// for relevant messages in the updated topic. // for relevant messages in the updated topic.
const filter = message_lists.current?.data.filter; const filter = message_lists.current?.data.filter;
if ( if (filter_has_term_type(filter, "is-followed")) {
filter !== undefined &&
(filter.sorted_term_types().includes("is-followed") ||
filter.sorted_term_types().includes("not-is-followed"))
) {
// Use `set_timeout to call after we update the topic // Use `set_timeout to call after we update the topic
// visibility policy locally. // visibility policy locally.
// Calling this outside `user_topics_ui` to avoid circular imports. // Calling this outside `user_topics_ui` to avoid circular imports.