refactor: Rename `stream_sort.js` to `stream_list_sort.js`.

Renamed `stream_sort` to `stream_list_sort` to make it clear that this
module is part of the stream_list bundle of modules.
This commit is contained in:
Lalit 2023-04-24 11:07:18 +05:30 committed by Tim Abbott
parent 2996e8e722
commit 9cad825d95
12 changed files with 78 additions and 78 deletions

View File

@ -62,8 +62,8 @@ import * as starred_messages from "./starred_messages";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_events from "./stream_events"; import * as stream_events from "./stream_events";
import * as stream_list from "./stream_list"; import * as stream_list from "./stream_list";
import * as stream_list_sort from "./stream_list_sort";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as stream_sort from "./stream_sort";
import * as stream_topic_history from "./stream_topic_history"; import * as stream_topic_history from "./stream_topic_history";
import * as stream_ui_updates from "./stream_ui_updates"; import * as stream_ui_updates from "./stream_ui_updates";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
@ -669,7 +669,7 @@ export function dispatch_normal_event(event) {
} }
if (event.property === "demote_inactive_streams") { if (event.property === "demote_inactive_streams") {
stream_list.update_streams_sidebar(); stream_list.update_streams_sidebar();
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
} }
if (event.property === "user_list_style") { if (event.property === "user_list_style") {
settings_display.report_user_list_style_change( settings_display.report_user_list_style_change(

View File

@ -20,8 +20,8 @@ import * as resize from "./resize";
import * as scroll_util from "./scroll_util"; import * as scroll_util from "./scroll_util";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_list_sort from "./stream_list_sort";
import * as stream_popover from "./stream_popover"; import * as stream_popover from "./stream_popover";
import * as stream_sort from "./stream_sort";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as topic_list from "./topic_list"; import * as topic_list from "./topic_list";
import * as topic_zoom from "./topic_zoom"; import * as topic_zoom from "./topic_zoom";
@ -160,9 +160,9 @@ export function build_stream_list(force_rerender) {
return; return;
} }
// The main logic to build the list is in stream_sort.js, and // The main logic to build the list is in stream_list_sort.js, and
// we get five lists of streams (pinned/normal/muted_pinned/muted_normal/dormant). // we get five lists of streams (pinned/normal/muted_pinned/muted_normal/dormant).
const stream_groups = stream_sort.sort_groups(streams, get_search_term()); const stream_groups = stream_list_sort.sort_groups(streams, get_search_term());
if (stream_groups.same_as_before && !force_rerender) { if (stream_groups.same_as_before && !force_rerender) {
return; return;
@ -374,7 +374,7 @@ class StreamSidebarRow {
} }
update_whether_active() { update_whether_active() {
if (stream_sort.has_recent_activity(this.sub) || this.sub.pin_to_top === true) { if (stream_list_sort.has_recent_activity(this.sub) || this.sub.pin_to_top === true) {
this.$list_item.removeClass("inactive_stream"); this.$list_item.removeClass("inactive_stream");
} else { } else {
this.$list_item.addClass("inactive_stream"); this.$list_item.addClass("inactive_stream");
@ -718,9 +718,9 @@ export function set_event_handlers() {
const li = get_stream_li(stream_id); const li = get_stream_li(stream_id);
return li; return li;
}, },
first_key: stream_sort.first_stream_id, first_key: stream_list_sort.first_stream_id,
prev_key: stream_sort.prev_stream_id, prev_key: stream_list_sort.prev_stream_id,
next_key: stream_sort.next_stream_id, next_key: stream_list_sort.next_stream_id,
}, },
highlight_class: "highlighted_stream", highlight_class: "highlighted_stream",
}); });

View File

@ -1,6 +1,6 @@
import * as pm_conversations from "./pm_conversations"; import * as pm_conversations from "./pm_conversations";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_sort from "./stream_sort"; import * as stream_list_sort from "./stream_list_sort";
import * as stream_topic_history from "./stream_topic_history"; import * as stream_topic_history from "./stream_topic_history";
import * as unread from "./unread"; import * as unread from "./unread";
import * as user_topics from "./user_topics"; import * as user_topics from "./user_topics";
@ -50,7 +50,7 @@ export function next_topic(streams, get_topics, has_unread_messages, curr_stream
} }
export function get_next_topic(curr_stream, curr_topic) { export function get_next_topic(curr_stream, curr_topic) {
let my_streams = stream_sort.get_streams(); let my_streams = stream_list_sort.get_streams();
my_streams = my_streams.filter((stream_name) => { my_streams = my_streams.filter((stream_name) => {
if (!stream_data.is_stream_muted_by_name(stream_name)) { if (!stream_data.is_stream_muted_by_name(stream_name)) {
@ -99,7 +99,7 @@ export function get_next_unread_pm_string(curr_pm) {
} }
export function get_next_stream(curr_stream) { export function get_next_stream(curr_stream) {
const my_streams = stream_sort.get_streams(); const my_streams = stream_list_sort.get_streams();
const curr_stream_index = my_streams.indexOf(curr_stream); const curr_stream_index = my_streams.indexOf(curr_stream);
return my_streams[ return my_streams[
curr_stream_index < 0 || curr_stream_index === my_streams.length - 1 curr_stream_index < 0 || curr_stream_index === my_streams.length - 1
@ -109,7 +109,7 @@ export function get_next_stream(curr_stream) {
} }
export function get_prev_stream(curr_stream) { export function get_prev_stream(curr_stream) {
const my_streams = stream_sort.get_streams(); const my_streams = stream_list_sort.get_streams();
const curr_stream_index = my_streams.indexOf(curr_stream); const curr_stream_index = my_streams.indexOf(curr_stream);
return my_streams[curr_stream_index <= 0 ? my_streams.length - 1 : curr_stream_index - 1]; return my_streams[curr_stream_index <= 0 ? my_streams.length - 1 : curr_stream_index - 1];
} }

View File

@ -11,7 +11,7 @@ import * as people from "./people";
import * as pm_conversations from "./pm_conversations"; import * as pm_conversations from "./pm_conversations";
import * as recent_senders from "./recent_senders"; import * as recent_senders from "./recent_senders";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_sort from "./stream_sort"; import * as stream_list_sort from "./stream_list_sort";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import * as user_status from "./user_status"; import * as user_status from "./user_status";
import * as util from "./util"; import * as util from "./util";
@ -432,7 +432,7 @@ function activity_score(sub) {
stream_score += 2; stream_score += 2;
} }
// Note: A pinned stream may accumulate a 3rd point if it has recent activity. // Note: A pinned stream may accumulate a 3rd point if it has recent activity.
if (stream_sort.has_recent_activity(sub)) { if (stream_list_sort.has_recent_activity(sub)) {
stream_score += 1; stream_score += 1;
} }
} }

View File

@ -93,8 +93,8 @@ import * as stream_data from "./stream_data";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
import * as stream_edit_subscribers from "./stream_edit_subscribers"; import * as stream_edit_subscribers from "./stream_edit_subscribers";
import * as stream_list from "./stream_list"; import * as stream_list from "./stream_list";
import * as stream_list_sort from "./stream_list_sort";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as stream_sort from "./stream_sort";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as tippyjs from "./tippyjs"; import * as tippyjs from "./tippyjs";
import * as topic_list from "./topic_list"; import * as topic_list from "./topic_list";
@ -640,7 +640,7 @@ export function initialize_everything() {
stream_settings_ui.initialize(); stream_settings_ui.initialize();
user_group_settings_ui.initialize(); user_group_settings_ui.initialize();
stream_list.initialize(); stream_list.initialize();
stream_sort.initialize(); stream_list_sort.initialize();
condense.initialize(); condense.initialize();
spoilers.initialize(); spoilers.initialize();
lightbox.initialize(); lightbox.initialize();

View File

@ -40,7 +40,7 @@ const people = zrequire("people");
const user_groups = zrequire("user_groups"); const user_groups = zrequire("user_groups");
const stream_bar = zrequire("stream_bar"); const stream_bar = zrequire("stream_bar");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const stream_sort = zrequire("stream_sort"); const stream_list_sort = zrequire("stream_list_sort");
const compose = zrequire("compose"); const compose = zrequire("compose");
const compose_pm_pill = zrequire("compose_pm_pill"); const compose_pm_pill = zrequire("compose_pm_pill");
const compose_ui = zrequire("compose_ui"); const compose_ui = zrequire("compose_ui");
@ -1064,7 +1064,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
settings_config.demote_inactive_streams_values.never.code, settings_config.demote_inactive_streams_values.never.code,
); );
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
fake_this = {completing: "stream", token: "s"}; fake_this = {completing: "stream", token: "s"};
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]); actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
expected_value = [sweden_stream, serbia_stream]; expected_value = [sweden_stream, serbia_stream];
@ -1076,7 +1076,7 @@ test("initialize", ({override, override_rewire, mock_template}) => {
settings_config.demote_inactive_streams_values.always.code, settings_config.demote_inactive_streams_values.always.code,
); );
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]); actual_value = sort_items(fake_this, [sweden_stream, serbia_stream]);
expected_value = [sweden_stream, serbia_stream]; expected_value = [sweden_stream, serbia_stream];
assert.deepEqual(actual_value, expected_value); assert.deepEqual(actual_value, expected_value);

View File

@ -63,7 +63,7 @@ const stream_data = mock_esm("../src/stream_data");
const stream_events = mock_esm("../src/stream_events"); const stream_events = mock_esm("../src/stream_events");
const stream_list = mock_esm("../src/stream_list"); const stream_list = mock_esm("../src/stream_list");
const stream_settings_ui = mock_esm("../src/stream_settings_ui"); const stream_settings_ui = mock_esm("../src/stream_settings_ui");
const stream_sort = mock_esm("../src/stream_sort"); const stream_list_sort = mock_esm("../src/stream_list_sort");
const stream_topic_history = mock_esm("../src/stream_topic_history"); const stream_topic_history = mock_esm("../src/stream_topic_history");
const submessage = mock_esm("../src/submessage"); const submessage = mock_esm("../src/submessage");
mock_esm("../src/top_left_corner", { mock_esm("../src/top_left_corner", {
@ -918,7 +918,7 @@ run_test("user_settings", ({override}) => {
{ {
const stub = make_stub(); const stub = make_stub();
event = event_fixtures.user_settings__demote_inactive_streams; event = event_fixtures.user_settings__demote_inactive_streams;
override(stream_sort, "set_filter_out_inactives", noop); override(stream_list_sort, "set_filter_out_inactives", noop);
override(stream_list, "update_streams_sidebar", stub.f); override(stream_list, "update_streams_sidebar", stub.f);
user_settings.demote_inactive_streams = 1; user_settings.demote_inactive_streams = 1;
dispatch(event); dispatch(event);

View File

@ -40,9 +40,9 @@ mock_esm("../src/unread", {
}); });
const {Filter} = zrequire("../src/filter"); const {Filter} = zrequire("../src/filter");
const stream_sort = zrequire("stream_sort");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const stream_list = zrequire("stream_list"); const stream_list = zrequire("stream_list");
const stream_list_sort = zrequire("stream_list_sort");
const devel = { const devel = {
name: "devel", name: "devel",
@ -200,11 +200,11 @@ test_ui("create_sidebar_row", ({override_rewire, mock_template}) => {
assert.ok(!$social_li.hasClass("out_of_home_view")); assert.ok(!$social_li.hasClass("out_of_home_view"));
const row = stream_list.stream_sidebar.get_row(stream_id); const row = stream_list.stream_sidebar.get_row(stream_id);
override_rewire(stream_sort, "has_recent_activity", () => true); override_rewire(stream_list_sort, "has_recent_activity", () => true);
row.update_whether_active(); row.update_whether_active();
assert.ok(!$social_li.hasClass("inactive_stream")); assert.ok(!$social_li.hasClass("inactive_stream"));
override_rewire(stream_sort, "has_recent_activity", () => false); override_rewire(stream_list_sort, "has_recent_activity", () => false);
row.update_whether_active(); row.update_whether_active();
assert.ok($social_li.hasClass("inactive_stream")); assert.ok($social_li.hasClass("inactive_stream"));
@ -229,16 +229,16 @@ test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
const $social_sidebar = $("<social-sidebar-row-stub>"); const $social_sidebar = $("<social-sidebar-row-stub>");
let stream_id = social.stream_id; let stream_id = social.stream_id;
let row = stream_list.stream_sidebar.get_row(stream_id); let row = stream_list.stream_sidebar.get_row(stream_id);
override_rewire(stream_sort, "has_recent_activity", () => false); override_rewire(stream_list_sort, "has_recent_activity", () => false);
stream_list.build_stream_list(); stream_list.build_stream_list();
assert.ok($social_sidebar.hasClass("inactive_stream")); assert.ok($social_sidebar.hasClass("inactive_stream"));
override_rewire(stream_sort, "has_recent_activity", () => true); override_rewire(stream_list_sort, "has_recent_activity", () => true);
row.update_whether_active(); row.update_whether_active();
assert.ok(!$social_sidebar.hasClass("inactive_stream")); assert.ok(!$social_sidebar.hasClass("inactive_stream"));
override_rewire(stream_sort, "has_recent_activity", () => false); override_rewire(stream_list_sort, "has_recent_activity", () => false);
row.update_whether_active(); row.update_whether_active();
assert.ok($social_sidebar.hasClass("inactive_stream")); assert.ok($social_sidebar.hasClass("inactive_stream"));
@ -246,7 +246,7 @@ test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
const $devel_sidebar = $("<devel-sidebar-row-stub>"); const $devel_sidebar = $("<devel-sidebar-row-stub>");
stream_id = devel.stream_id; stream_id = devel.stream_id;
row = stream_list.stream_sidebar.get_row(stream_id); row = stream_list.stream_sidebar.get_row(stream_id);
override_rewire(stream_sort, "has_recent_activity", () => false); override_rewire(stream_list_sort, "has_recent_activity", () => false);
stream_list.build_stream_list(); stream_list.build_stream_list();
assert.ok(!$devel_sidebar.hasClass("inactive_stream")); assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
@ -499,7 +499,7 @@ test_ui("sort_streams", ({override_rewire, mock_template}) => {
initialize_stream_data(); initialize_stream_data();
override_rewire(stream_sort, "has_recent_activity", (sub) => sub.name !== "cars"); override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "cars");
let appended_elems; let appended_elems;
$("#stream_filters").append = (elems) => { $("#stream_filters").append = (elems) => {
@ -528,7 +528,7 @@ test_ui("sort_streams", ({override_rewire, mock_template}) => {
assert.ok(active_subheader_flag); assert.ok(active_subheader_flag);
assert.ok(inactive_subheader_flag); assert.ok(inactive_subheader_flag);
const streams = stream_sort.get_streams(); const streams = stream_list_sort.get_streams();
assert.deepEqual(streams, [ assert.deepEqual(streams, [
// three groups: pinned, normal, dormant // three groups: pinned, normal, dormant
@ -587,7 +587,7 @@ test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template})
}; };
add_row(DenmarkSub); add_row(DenmarkSub);
override_rewire(stream_sort, "has_recent_activity", (sub) => sub.name !== "Denmark"); override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "Denmark");
let appended_elems; let appended_elems;
$("#stream_filters").append = (elems) => { $("#stream_filters").append = (elems) => {

View File

@ -11,7 +11,7 @@ const {user_settings} = require("./lib/zpage_params");
const people = zrequire("people"); const people = zrequire("people");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history"); const stream_topic_history = zrequire("stream_topic_history");
const stream_sort = zrequire("stream_sort"); const stream_list_sort = zrequire("stream_list_sort");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
function contains_sub(subs, sub) { function contains_sub(subs, sub) {
@ -77,7 +77,7 @@ const muted_pinned = {
function sort_groups(query) { function sort_groups(query) {
const streams = stream_data.subscribed_stream_ids(); const streams = stream_data.subscribed_stream_ids();
return stream_sort.sort_groups(streams, query); return stream_list_sort.sort_groups(streams, query);
} }
function test(label, f) { function test(label, f) {
@ -97,7 +97,7 @@ test("no_subscribed_streams", () => {
pinned_streams: [], pinned_streams: [],
same_as_before: sorted.same_as_before, same_as_before: sorted.same_as_before,
}); });
assert.equal(stream_sort.first_stream_id(), undefined); assert.equal(stream_list_sort.first_stream_id(), undefined);
}); });
test("basics", ({override_rewire}) => { test("basics", ({override_rewire}) => {
@ -110,7 +110,7 @@ test("basics", ({override_rewire}) => {
stream_data.add_sub(muted_active); stream_data.add_sub(muted_active);
stream_data.add_sub(muted_pinned); stream_data.add_sub(muted_pinned);
override_rewire(stream_sort, "has_recent_activity", (sub) => sub.name !== "pneumonia"); override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "pneumonia");
// Test sorting into categories/alphabetized // Test sorting into categories/alphabetized
let sorted = sort_groups(""); let sorted = sort_groups("");
@ -125,26 +125,26 @@ test("basics", ({override_rewire}) => {
assert.deepEqual(sorted.dormant_streams, [pneumonia.stream_id]); assert.deepEqual(sorted.dormant_streams, [pneumonia.stream_id]);
// Test cursor helpers. // Test cursor helpers.
assert.equal(stream_sort.first_stream_id(), scalene.stream_id); assert.equal(stream_list_sort.first_stream_id(), scalene.stream_id);
assert.equal(stream_sort.prev_stream_id(scalene.stream_id), undefined); assert.equal(stream_list_sort.prev_stream_id(scalene.stream_id), undefined);
assert.equal(stream_sort.prev_stream_id(muted_pinned.stream_id), scalene.stream_id); assert.equal(stream_list_sort.prev_stream_id(muted_pinned.stream_id), scalene.stream_id);
assert.equal(stream_sort.prev_stream_id(clarinet.stream_id), muted_pinned.stream_id); assert.equal(stream_list_sort.prev_stream_id(clarinet.stream_id), muted_pinned.stream_id);
assert.equal( assert.equal(
stream_sort.next_stream_id(fast_tortoise.stream_id), stream_list_sort.next_stream_id(fast_tortoise.stream_id),
stream_hyphen_underscore_slash.stream_id, stream_hyphen_underscore_slash.stream_id,
); );
assert.equal( assert.equal(
stream_sort.next_stream_id(stream_hyphen_underscore_slash.stream_id), stream_list_sort.next_stream_id(stream_hyphen_underscore_slash.stream_id),
muted_active.stream_id, muted_active.stream_id,
); );
assert.equal( assert.equal(
stream_sort.next_stream_id(fast_tortoise.stream_id), stream_list_sort.next_stream_id(fast_tortoise.stream_id),
stream_hyphen_underscore_slash.stream_id, stream_hyphen_underscore_slash.stream_id,
); );
assert.equal(stream_sort.next_stream_id(muted_active.stream_id), pneumonia.stream_id); assert.equal(stream_list_sort.next_stream_id(muted_active.stream_id), pneumonia.stream_id);
assert.equal(stream_sort.next_stream_id(pneumonia.stream_id), undefined); assert.equal(stream_list_sort.next_stream_id(pneumonia.stream_id), undefined);
// Test filtering // Test filtering
sorted = sort_groups("s"); sorted = sort_groups("s");
@ -152,9 +152,9 @@ test("basics", ({override_rewire}) => {
assert.deepEqual(sorted.normal_streams, [stream_hyphen_underscore_slash.stream_id]); assert.deepEqual(sorted.normal_streams, [stream_hyphen_underscore_slash.stream_id]);
assert.deepEqual(sorted.dormant_streams, []); assert.deepEqual(sorted.dormant_streams, []);
assert.equal(stream_sort.prev_stream_id(clarinet.stream_id), undefined); assert.equal(stream_list_sort.prev_stream_id(clarinet.stream_id), undefined);
assert.equal(stream_sort.next_stream_id(clarinet.stream_id), undefined); assert.equal(stream_list_sort.next_stream_id(clarinet.stream_id), undefined);
// Test searching entire word, case-insensitive // Test searching entire word, case-insensitive
sorted = sort_groups("PnEuMoNiA"); sorted = sort_groups("PnEuMoNiA");
@ -202,24 +202,24 @@ test("has_recent_activity", () => {
user_settings.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.automatic.code; settings_config.demote_inactive_streams_values.automatic.code;
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
sub = {name: "pets", subscribed: false, stream_id: 111}; sub = {name: "pets", subscribed: false, stream_id: 111};
stream_data.add_sub(sub); stream_data.add_sub(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_data.subscribe_myself(sub); stream_data.subscribe_myself(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
assert.ok(contains_sub(stream_data.subscribed_subs(), sub)); assert.ok(contains_sub(stream_data.subscribed_subs(), sub));
assert.ok(!contains_sub(stream_data.unsubscribed_subs(), sub)); assert.ok(!contains_sub(stream_data.unsubscribed_subs(), sub));
stream_data.unsubscribe_myself(sub); stream_data.unsubscribe_myself(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
sub.pin_to_top = true; sub.pin_to_top = true;
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
sub.pin_to_top = false; sub.pin_to_top = false;
const opts = { const opts = {
@ -229,72 +229,72 @@ test("has_recent_activity", () => {
}; };
stream_topic_history.add_message(opts); stream_topic_history.add_message(opts);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
user_settings.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.always.code; settings_config.demote_inactive_streams_values.always.code;
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
sub = {name: "pets", subscribed: false, stream_id: 111}; sub = {name: "pets", subscribed: false, stream_id: 111};
stream_data.add_sub(sub); stream_data.add_sub(sub);
assert.ok(!stream_sort.has_recent_activity(sub)); assert.ok(!stream_list_sort.has_recent_activity(sub));
sub.pin_to_top = true; sub.pin_to_top = true;
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
sub.pin_to_top = false; sub.pin_to_top = false;
stream_data.subscribe_myself(sub); stream_data.subscribe_myself(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_data.unsubscribe_myself(sub); stream_data.unsubscribe_myself(sub);
assert.ok(!stream_sort.has_recent_activity(sub)); assert.ok(!stream_list_sort.has_recent_activity(sub));
sub = {name: "lunch", subscribed: false, stream_id: 222}; sub = {name: "lunch", subscribed: false, stream_id: 222};
stream_data.add_sub(sub); stream_data.add_sub(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_topic_history.add_message(opts); stream_topic_history.add_message(opts);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
user_settings.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.never.code; settings_config.demote_inactive_streams_values.never.code;
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
sub = {name: "pets", subscribed: false, stream_id: 111}; sub = {name: "pets", subscribed: false, stream_id: 111};
stream_data.add_sub(sub); stream_data.add_sub(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_data.subscribe_myself(sub); stream_data.subscribe_myself(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_data.unsubscribe_myself(sub); stream_data.unsubscribe_myself(sub);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
sub.pin_to_top = true; sub.pin_to_top = true;
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
stream_topic_history.add_message(opts); stream_topic_history.add_message(opts);
assert.ok(stream_sort.has_recent_activity(sub)); assert.ok(stream_list_sort.has_recent_activity(sub));
}); });
test("has_recent_activity_but_muted", () => { test("has_recent_activity_but_muted", () => {
const sub = {name: "cats", subscribed: true, stream_id: 111, is_muted: true}; const sub = {name: "cats", subscribed: true, stream_id: 111, is_muted: true};
stream_data.add_sub(sub); stream_data.add_sub(sub);
assert.ok(stream_sort.has_recent_activity_but_muted(sub)); assert.ok(stream_list_sort.has_recent_activity_but_muted(sub));
}); });
test("filter inactives", () => { test("filter inactives", () => {
user_settings.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.automatic.code; settings_config.demote_inactive_streams_values.automatic.code;
assert.ok(!stream_sort.is_filtering_inactives()); assert.ok(!stream_list_sort.is_filtering_inactives());
_.times(30, (i) => { _.times(30, (i) => {
const name = "random" + i.toString(); const name = "random" + i.toString();
@ -308,14 +308,14 @@ test("filter inactives", () => {
}; };
stream_data.add_sub(sub); stream_data.add_sub(sub);
}); });
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
assert.ok(stream_sort.is_filtering_inactives()); assert.ok(stream_list_sort.is_filtering_inactives());
}); });
test("initialize", () => { test("initialize", () => {
user_settings.demote_inactive_streams = 1; user_settings.demote_inactive_streams = 1;
stream_sort.initialize(); stream_list_sort.initialize();
assert.ok(!stream_sort.is_filtering_inactives()); assert.ok(!stream_list_sort.is_filtering_inactives());
}); });

View File

@ -13,7 +13,7 @@ const unread = mock_esm("../src/unread");
const pm_conversations = zrequire("pm_conversations"); const pm_conversations = zrequire("pm_conversations");
pm_conversations.recent = {}; pm_conversations.recent = {};
const stream_sort = zrequire("stream_sort"); const stream_list_sort = zrequire("stream_list_sort");
const tg = zrequire("topic_generator"); const tg = zrequire("topic_generator");
run_test("streams", () => { run_test("streams", () => {
@ -22,7 +22,7 @@ run_test("streams", () => {
assert.equal(actual, expected); assert.equal(actual, expected);
} }
stream_sort.get_streams = () => ["announce", "muted", "devel", "test here"]; stream_list_sort.get_streams = () => ["announce", "muted", "devel", "test here"];
assert_next_stream(undefined, "announce"); assert_next_stream(undefined, "announce");
assert_next_stream("NOT THERE", "announce"); assert_next_stream("NOT THERE", "announce");
@ -74,9 +74,9 @@ run_test("topics", ({override}) => {
); );
// Now test the deeper function that is wired up to // Now test the deeper function that is wired up to
// real functions stream_data/stream_sort/unread. // real functions stream_data/stream_list_sort/unread.
stream_sort.get_streams = () => ["announce", "muted", "devel", "test here"]; stream_list_sort.get_streams = () => ["announce", "muted", "devel", "test here"];
const muted_stream_id = 400; const muted_stream_id = 400;
const devel_stream_id = 401; const devel_stream_id = 401;

View File

@ -15,7 +15,7 @@ const recent_senders = zrequire("recent_senders");
const peer_data = zrequire("peer_data"); const peer_data = zrequire("peer_data");
const people = zrequire("people"); const people = zrequire("people");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const stream_sort = zrequire("stream_sort"); const stream_list_sort = zrequire("stream_list_sort");
const compose_state = zrequire("compose_state"); const compose_state = zrequire("compose_state");
const emoji = zrequire("emoji"); const emoji = zrequire("emoji");
const pygments_data = zrequire("../generated/pygments_data.json"); const pygments_data = zrequire("../generated/pygments_data.json");
@ -158,7 +158,7 @@ test("sort_streams", ({override}) => {
settings_config.demote_inactive_streams_values.always.code, settings_config.demote_inactive_streams_values.always.code,
); );
stream_sort.set_filter_out_inactives(); stream_list_sort.set_filter_out_inactives();
override( override(
stream_topic_history, stream_topic_history,
"stream_has_topics", "stream_has_topics",