inbox_ui: Extract FILTERS to views_util.

Same FILTERS will also be used in recent view.
This commit is contained in:
Aman Agrawal
2023-11-22 18:04:34 +00:00
committed by Tim Abbott
parent 59d56c5615
commit 2c76ef9a73
2 changed files with 17 additions and 17 deletions

View File

@@ -38,12 +38,6 @@ let streams_dict = new Map();
let update_triggered_by_user = false; let update_triggered_by_user = false;
let filters_dropdown_widget; let filters_dropdown_widget;
const FILTERS = {
ALL_TOPICS: "all_topics",
UNMUTED_TOPICS: "unmuted_topics",
FOLLOWED_TOPICS: "followed_topics",
};
const COLUMNS = { const COLUMNS = {
COLLAPSE_BUTTON: 0, COLLAPSE_BUTTON: 0,
RECIPIENT: 1, RECIPIENT: 1,
@@ -58,7 +52,7 @@ const ls_filter_key = "inbox-filters";
const ls_collapsed_containers_key = "inbox_collapsed_containers"; const ls_collapsed_containers_key = "inbox_collapsed_containers";
const ls = localstorage(); const ls = localstorage();
let filters = new Set([FILTERS.UNMUTED_TOPICS]); let filters = new Set([views_util.FILTERS.UNMUTED_TOPICS]);
let collapsed_containers = new Set(); let collapsed_containers = new Set();
let search_keyword = ""; let search_keyword = "";
@@ -133,11 +127,11 @@ function get_stream_header_row(stream_id) {
function load_data_from_ls() { function load_data_from_ls() {
const saved_filters = new Set(ls.get(ls_filter_key)); const saved_filters = new Set(ls.get(ls_filter_key));
const valid_filters = new Set(Object.values(FILTERS)); const valid_filters = new Set(Object.values(views_util.FILTERS));
// If saved filters are not in the list of valid filters, we reset to default. // If saved filters are not in the list of valid filters, we reset to default.
const is_subset = [...saved_filters].every((filter) => valid_filters.has(filter)); const is_subset = [...saved_filters].every((filter) => valid_filters.has(filter));
if (saved_filters.size === 0 || !is_subset) { if (saved_filters.size === 0 || !is_subset) {
filters = new Set([FILTERS.UNMUTED_TOPICS]); filters = new Set([views_util.FILTERS.UNMUTED_TOPICS]);
} else { } else {
filters = saved_filters; filters = saved_filters;
} }
@@ -506,25 +500,25 @@ function show_empty_inbox_text(has_visible_unreads) {
function filters_dropdown_options() { function filters_dropdown_options() {
return [ return [
{ {
unique_id: FILTERS.ALL_TOPICS, unique_id: views_util.FILTERS.ALL_TOPICS,
name: $t({defaultMessage: "All topics"}), name: $t({defaultMessage: "All topics"}),
bold_current_selection: bold_current_selection:
filters_dropdown_widget && filters_dropdown_widget &&
filters_dropdown_widget.current_value === FILTERS.ALL_TOPICS, filters_dropdown_widget.current_value === views_util.FILTERS.ALL_TOPICS,
}, },
{ {
unique_id: FILTERS.UNMUTED_TOPICS, unique_id: views_util.FILTERS.UNMUTED_TOPICS,
name: $t({defaultMessage: "Unmuted topics"}), name: $t({defaultMessage: "Unmuted topics"}),
bold_current_selection: bold_current_selection:
filters_dropdown_widget && filters_dropdown_widget &&
filters_dropdown_widget.current_value === FILTERS.UNMUTED_TOPICS, filters_dropdown_widget.current_value === views_util.FILTERS.UNMUTED_TOPICS,
}, },
{ {
unique_id: FILTERS.FOLLOWED_TOPICS, unique_id: views_util.FILTERS.FOLLOWED_TOPICS,
name: $t({defaultMessage: "Followed topics"}), name: $t({defaultMessage: "Followed topics"}),
bold_current_selection: bold_current_selection:
filters_dropdown_widget && filters_dropdown_widget &&
filters_dropdown_widget.current_value === FILTERS.FOLLOWED_TOPICS, filters_dropdown_widget.current_value === views_util.FILTERS.FOLLOWED_TOPICS,
}, },
]; ];
} }
@@ -617,14 +611,14 @@ function filter_should_hide_row({stream_id, topic, dm_key}) {
} }
if ( if (
filters.has(FILTERS.FOLLOWED_TOPICS) && filters.has(views_util.FILTERS.FOLLOWED_TOPICS) &&
!user_topics.is_topic_followed(stream_id, topic) !user_topics.is_topic_followed(stream_id, topic)
) { ) {
return true; return true;
} }
if ( if (
filters.has(FILTERS.UNMUTED_TOPICS) && filters.has(views_util.FILTERS.UNMUTED_TOPICS) &&
(user_topics.is_topic_muted(stream_id, topic) || stream_data.is_muted(stream_id)) && (user_topics.is_topic_muted(stream_id, topic) || stream_data.is_muted(stream_id)) &&
!user_topics.is_topic_unmuted_or_followed(stream_id, topic) !user_topics.is_topic_unmuted_or_followed(stream_id, topic)
) { ) {

View File

@@ -12,6 +12,12 @@ import * as search from "./search";
import * as stream_list from "./stream_list"; import * as stream_list from "./stream_list";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
export const FILTERS = {
ALL_TOPICS: "all_topics",
UNMUTED_TOPICS: "unmuted_topics",
FOLLOWED_TOPICS: "followed_topics",
};
export function show(opts) { export function show(opts) {
if (narrow_state.has_shown_message_list_view) { if (narrow_state.has_shown_message_list_view) {
message_lists.save_pre_narrow_offset_for_reload(); message_lists.save_pre_narrow_offset_for_reload();