From 517fabd123afb71efe038e819cdbf42959d232e5 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 1 Nov 2024 23:38:23 +0530 Subject: [PATCH] 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. --- web/src/message_events.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/web/src/message_events.js b/web/src/message_events.js index e8550acb7a..21c83ec49c 100644 --- a/web/src/message_events.js +++ b/web/src/message_events.js @@ -39,17 +39,21 @@ import * as unread from "./unread"; import * as unread_ui from "./unread_ui"; 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() { // If we have rendered message list / cached data based on topic // 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 // for relevant messages in the updated topic. const filter = message_lists.current?.data.filter; - if ( - filter !== undefined && - (filter.sorted_term_types().includes("is-followed") || - filter.sorted_term_types().includes("not-is-followed")) - ) { + if (filter_has_term_type(filter, "is-followed")) { // Use `set_timeout to call after we update the topic // visibility policy locally. // Calling this outside `user_topics_ui` to avoid circular imports.