stream_list_sort: Fix user setting for demote inactive stream ignored.

We were not using `filter_out_inactives` and `pin_to_top` when
sorting stream in the left sidebar.

These were incorrectly removed in
1aee0ef98b.

Restored the original function and the places where it was used
to bring back original functionality.

(cherry picked from commit 67ff430e45)
This commit is contained in:
Aman Agrawal
2025-03-25 12:34:28 +05:30
committed by Tim Abbott
parent 30e52c90e5
commit f12d72d711
5 changed files with 43 additions and 5 deletions

View File

@@ -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");

View File

@@ -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 = [];

View File

@@ -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;

View File

@@ -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: "me@example.com",

View File

@@ -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}) => {