Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_list_sort: Fix user setting for demote inactive stream ignored.
Aman Agrawal67ff430e45e0
diff --git a/web/src/stream_list.ts b/web/src/stream_list.tsindex 46a69201650..728949b42e9 100644--- a/web/src/stream_list.ts+++ b/web/src/stream_list.ts@@ -485,7 +485,7 @@ class StreamSidebarRow {}update_whether_active(): void {- if (this.sub.is_recently_active || this.sub.pin_to_top) {+ if (stream_list_sort.has_recent_activity(this.sub)) {this.$list_item.removeClass("inactive_stream");} else {this.$list_item.addClass("inactive_stream");diff --git a/web/src/stream_list_sort.ts b/web/src/stream_list_sort.tsindex 3c349ec53dc..3b4da271350 100644--- a/web/src/stream_list_sort.ts+++ b/web/src/stream_list_sort.ts@@ -57,6 +57,20 @@ export function is_filtering_inactives(): boolean {return filter_out_inactives;}+export function has_recent_activity(sub: StreamSubscription): boolean {+ if (!filter_out_inactives || sub.pin_to_top) {+ // If users don't want to filter inactive streams+ // to the bottom, we respect that setting and don't+ // treat any streams as dormant.+ //+ // Currently this setting is automatically determined+ // by the number of streams. See the callers+ // to set_filter_out_inactives.+ return true;+ }+ return sub.is_recently_active || sub.newly_subscribed;+}+type StreamListSortResult = {same_as_before: boolean;pinned_streams: number[];@@ -78,7 +92,7 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi);function is_normal(sub: StreamSubscription): boolean {- return sub.is_recently_active;+ return has_recent_activity(sub);}const pinned_streams = [];diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.tsindex f06a57b176a..860ebe8a7cd 100644--- a/web/src/typeahead_helper.ts+++ b/web/src/typeahead_helper.ts@@ -23,6 +23,7 @@ import * as recent_senders from "./recent_senders.ts";import * as settings_config from "./settings_config.ts";import {realm} from "./state_data.ts";import * as stream_data from "./stream_data.ts";+import * as stream_list_sort from "./stream_list_sort.ts";import type {StreamPill, StreamPillData} from "./stream_pill.ts";import type {StreamSubscription} from "./sub_store.ts";import type {UserGroupPill, UserGroupPillData} from "./user_group_pill.ts";@@ -847,7 +848,7 @@ function activity_score(sub: StreamSubscription): number {if (sub.pin_to_top) {stream_score += 2;}- if (sub.is_recently_active) {+ if (stream_list_sort.has_recent_activity(sub)) {stream_score += 1;}return stream_score;diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjsindex 6484d9a3e76..9db22192374 100644--- a/web/tests/stream_list.test.cjs+++ b/web/tests/stream_list.test.cjs@@ -46,9 +46,14 @@ const stream_list = zrequire("stream_list");const stream_list_sort = zrequire("stream_list_sort");const user_groups = zrequire("user_groups");const {initialize_user_settings} = zrequire("user_settings");+const settings_config = zrequire("settings_config");-const user_settings = {};+// Start with always filtering out inactive streams.+const user_settings = {+ demote_inactive_streams: settings_config.demote_inactive_streams_values.always.code,+};initialize_user_settings({user_settings});+stream_list_sort.set_filter_out_inactives();const me = {email: "[email protected]",diff --git a/web/tests/stream_list_sort.test.cjs b/web/tests/stream_list_sort.test.cjsindex 07bf9e7f510..4a23bfb914f 100644--- a/web/tests/stream_list_sort.test.cjs+++ b/web/tests/stream_list_sort.test.cjs@@ -12,8 +12,12 @@ const stream_list_sort = zrequire("stream_list_sort");const settings_config = zrequire("settings_config");const {initialize_user_settings} = zrequire("user_settings");-const user_settings = {};+// Start with always filtering out inactive streams.+const user_settings = {+ demote_inactive_streams: settings_config.demote_inactive_streams_values.always.code,+};initialize_user_settings({user_settings});+stream_list_sort.set_filter_out_inactives();const scalene = {subscribed: true,@@ -202,12 +206,15 @@ test("basics", () => {});test("filter inactives", ({override}) => {+ // Test that we automatically switch to filtering out inactive streams+ // once the user has more than 30 streams.override(user_settings,"demote_inactive_streams",settings_config.demote_inactive_streams_values.automatic.code,);+ stream_list_sort.set_filter_out_inactives();assert.ok(!stream_list_sort.is_filtering_inactives());_.times(30, (i) => {@@ -225,6 +232,17 @@ test("filter inactives", ({override}) => {stream_list_sort.set_filter_out_inactives();assert.ok(stream_list_sort.is_filtering_inactives());++ override(+ user_settings,+ "demote_inactive_streams",+ settings_config.demote_inactive_streams_values.never.code,+ );+ stream_list_sort.set_filter_out_inactives();+ assert.ok(!stream_list_sort.is_filtering_inactives());+ // Even inactive channels are marked active.+ assert.ok(!pneumonia.is_recently_active);+ assert.ok(stream_list_sort.has_recent_activity(pneumonia));});test("initialize", ({override}) => {