mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
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 in1aee0ef98b. Restored the original function and the places where it was used to bring back original functionality. (cherry picked from commit67ff430e45)
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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}) => {
|
||||
|
||||
Reference in New Issue
Block a user