Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream: Use `is_recently_active` to check active status.

Aman Agrawal1aee0ef98b26
diff --git a/web/src/stream_events.ts b/web/src/stream_events.ts
index 6282b09347b..2877f741c49 100644
--- a/web/src/stream_events.ts
+++ b/web/src/stream_events.ts
@@ -45,11 +45,12 @@ function update_stream_setting(
| "push_notifications"
| "email_notifications"
| "wildcard_mentions_notify"
- | "pin_to_top",
+ | "pin_to_top"
+ | "is_recently_active",
): void {
const $setting_checkbox = $(`#${CSS.escape(setting)}_${CSS.escape(sub.stream_id.toString())}`);
$setting_checkbox.prop("checked", value);
- if (setting === "pin_to_top") {
+ if (setting === "pin_to_top" || setting === "is_recently_active") {
assert(value !== null);
sub[setting] = value;
return;
@@ -147,6 +148,10 @@ export function update_property<P extends keyof UpdatableStreamProperties>(
can_remove_subscribers_group(value) {
stream_settings_ui.update_can_remove_subscribers_group(sub, value);
},
+ is_recently_active(value) {
+ update_stream_setting(sub, value, "is_recently_active");
+ stream_list.update_streams_sidebar();
+ },
};
if (Object.hasOwn(updaters, property) && updaters[property] !== undefined) {
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index b2dabaea2be..670cdf1cfbe 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -485,7 +485,7 @@ class StreamSidebarRow {
}
update_whether_active(): void {
- if (stream_list_sort.has_recent_activity(this.sub) || this.sub.pin_to_top) {
+ if (this.sub.is_recently_active || this.sub.pin_to_top) {
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.ts
index 22465d1c0a6..a7418fa7f88 100644
--- a/web/src/stream_list_sort.ts
+++ b/web/src/stream_list_sort.ts
@@ -2,7 +2,6 @@ import assert from "minimalistic-assert";
import * as settings_config from "./settings_config.ts";
import * as stream_data from "./stream_data.ts";
-import * as stream_topic_history from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
import type {StreamSubscription} from "./sub_store.ts";
import {user_settings} from "./user_settings.ts";
@@ -58,26 +57,8 @@ export function is_filtering_inactives(): boolean {
return filter_out_inactives;
}
-export let 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 stream_topic_history.stream_has_topics(sub.stream_id) || sub.newly_subscribed;
-};
-
-export function rewire_has_recent_activity(value: typeof has_recent_activity): void {
- has_recent_activity = value;
-}
-
export function has_recent_activity_but_muted(sub: StreamSubscription): boolean {
- return has_recent_activity(sub) && sub.is_muted;
+ return sub.is_recently_active && sub.is_muted;
}
type StreamListSortResult = {
@@ -101,7 +82,7 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi
);
function is_normal(sub: StreamSubscription): boolean {
- return has_recent_activity(sub);
+ return sub.is_recently_active;
}
const pinned_streams = [];
diff --git a/web/src/stream_types.ts b/web/src/stream_types.ts
index f66f321439b..bbb09ef851e 100644
--- a/web/src/stream_types.ts
+++ b/web/src/stream_types.ts
@@ -31,6 +31,7 @@ export const stream_schema = z.object({
MODERATORS: StreamPostPolicy.MODERATORS,
}),
can_remove_subscribers_group: group_setting_value_schema,
+ is_recently_active: z.boolean(),
});
export const stream_specific_notification_settings_schema = z.object({
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index b03e18f8913..4a53b7b6fd5 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -18,7 +18,6 @@ import * as pygments_data from "./pygments_data.ts";
import * as recent_senders from "./recent_senders.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";
@@ -783,7 +782,7 @@ function activity_score(sub: StreamSubscription): number {
if (sub.pin_to_top) {
stream_score += 2;
}
- if (stream_list_sort.has_recent_activity(sub)) {
+ if (sub.is_recently_active) {
stream_score += 1;
}
return stream_score;
diff --git a/web/tests/lib/events.cjs b/web/tests/lib/events.cjs
index 49db2ec8ba1..20e2601d4c1 100644
--- a/web/tests/lib/events.cjs
+++ b/web/tests/lib/events.cjs
@@ -55,6 +55,7 @@ exports.test_streams = {
message_retention_days: null,
stream_post_policy: 1,
can_remove_subscribers_group: 2,
+ is_recently_active: true,
},
test: {
is_archived: false,
@@ -72,6 +73,7 @@ exports.test_streams = {
message_retention_days: null,
stream_post_policy: 1,
can_remove_subscribers_group: 2,
+ is_recently_active: true,
},
};
diff --git a/web/tests/stream_events.test.cjs b/web/tests/stream_events.test.cjs
index e8d5a0fb282..392cf0a715f 100644
--- a/web/tests/stream_events.test.cjs
+++ b/web/tests/stream_events.test.cjs
@@ -221,6 +221,16 @@ test("update_property", ({override}) => {
assert.equal($checkbox.prop("checked"), true);
}
+ // Test change in stream active status
+ {
+ let sidebar_updated_for_stream_active_status = false;
+ override(stream_list, "update_streams_sidebar", () => {
+ sidebar_updated_for_stream_active_status = true;
+ });
+ stream_events.update_property(stream_id, "is_recently_active", false);
+ assert.equal(sidebar_updated_for_stream_active_status, true);
+ }
+
// Test stream privacy change event
{
const stub = make_stub();
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index 2ffb78575e8..028739b456c 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -60,6 +60,7 @@ const devel = {
color: "blue",
subscribed: true,
pin_to_top: true,
+ is_recently_active: false,
};
const social = {
@@ -67,6 +68,7 @@ const social = {
stream_id: 200,
color: "green",
subscribed: true,
+ is_recently_active: true,
};
// flag to check if subheader is rendered
@@ -144,7 +146,7 @@ function test_ui(label, f) {
});
}
-test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => {
+test_ui("create_sidebar_row", ({override, mock_template}) => {
// Make a couple calls to create_sidebar_row() and make sure they
// generate the right markup as well as play nice with get_stream_li().
override(user_settings, "demote_inactive_streams", 1);
@@ -212,11 +214,11 @@ test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => {
assert.ok(!$social_li.hasClass("out_of_home_view"));
const row = stream_list.stream_sidebar.get_row(stream_id);
- override_rewire(stream_list_sort, "has_recent_activity", () => true);
+ social.is_recently_active = true;
row.update_whether_active();
assert.ok(!$social_li.hasClass("inactive_stream"));
- override_rewire(stream_list_sort, "has_recent_activity", () => false);
+ social.is_recently_active = false;
row.update_whether_active();
assert.ok($social_li.hasClass("inactive_stream"));
@@ -229,7 +231,7 @@ test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => {
assert.ok(removed);
});
-test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
+test_ui("pinned_streams_never_inactive", ({mock_template}) => {
stream_data.add_sub(devel);
stream_data.add_sub(social);
@@ -241,16 +243,16 @@ test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
const $social_sidebar = $("<social-sidebar-row-stub>");
let stream_id = social.stream_id;
let row = stream_list.stream_sidebar.get_row(stream_id);
- override_rewire(stream_list_sort, "has_recent_activity", () => false);
+ social.is_recently_active = false;
stream_list.build_stream_list();
assert.ok($social_sidebar.hasClass("inactive_stream"));
- override_rewire(stream_list_sort, "has_recent_activity", () => true);
+ social.is_recently_active = true;
row.update_whether_active();
assert.ok(!$social_sidebar.hasClass("inactive_stream"));
- override_rewire(stream_list_sort, "has_recent_activity", () => false);
+ social.is_recently_active = false;
row.update_whether_active();
assert.ok($social_sidebar.hasClass("inactive_stream"));
@@ -258,7 +260,7 @@ test_ui("pinned_streams_never_inactive", ({override_rewire, mock_template}) => {
const $devel_sidebar = $("<devel-sidebar-row-stub>");
stream_id = devel.stream_id;
row = stream_list.stream_sidebar.get_row(stream_id);
- override_rewire(stream_list_sort, "has_recent_activity", () => false);
+ social.is_recently_active = false;
stream_list.build_stream_list();
assert.ok(!$devel_sidebar.hasClass("inactive_stream"));
@@ -289,6 +291,7 @@ const develSub = {
color: "blue",
pin_to_top: true,
subscribed: true,
+ is_recently_active: true,
};
const RomeSub = {
@@ -297,6 +300,7 @@ const RomeSub = {
color: "blue",
pin_to_top: true,
subscribed: true,
+ is_recently_active: true,
};
const testSub = {
@@ -305,6 +309,7 @@ const testSub = {
color: "blue",
pin_to_top: true,
subscribed: true,
+ is_recently_active: true,
};
const announceSub = {
@@ -313,6 +318,7 @@ const announceSub = {
color: "green",
pin_to_top: false,
subscribed: true,
+ is_recently_active: true,
};
const DenmarkSub = {
@@ -321,6 +327,7 @@ const DenmarkSub = {
color: "green",
pin_to_top: false,
subscribed: true,
+ is_recently_active: true,
};
const carSub = {
@@ -329,6 +336,7 @@ const carSub = {
color: "green",
pin_to_top: false,
subscribed: true,
+ is_recently_active: false,
};
function initialize_stream_data() {
@@ -499,7 +507,7 @@ test_ui("focus_user_filter", () => {
click_handler(e);
});
-test_ui("sort_streams", ({override_rewire, mock_template}) => {
+test_ui("sort_streams", ({mock_template}) => {
create_stream_subheader({mock_template});
// Set subheader flag to false
pinned_subheader_flag = false;
@@ -511,14 +519,12 @@ test_ui("sort_streams", ({override_rewire, mock_template}) => {
initialize_stream_data();
- override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "cars");
-
let appended_elems;
$("#stream_filters").append = (elems) => {
appended_elems = elems;
};
- stream_list.build_stream_list();
+ stream_list.build_stream_list(true);
const $pinned_subheader = $("<pinned-subheader-stub>");
const $active_subheader = $("<active-subheader-stub>");
@@ -561,7 +567,7 @@ test_ui("sort_streams", ({override_rewire, mock_template}) => {
assert.ok(!stream_list.stream_sidebar.has_row_for(stream_id));
});
-test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template}) => {
+test_ui("separators_only_pinned_and_dormant", ({mock_template}) => {
// Test only pinned and dormant streams
create_stream_subheader({mock_template});
@@ -578,6 +584,7 @@ test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template})
color: "blue",
pin_to_top: true,
subscribed: true,
+ is_recently_active: true,
};
add_row(develSub);
@@ -587,6 +594,7 @@ test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template})
color: "blue",
pin_to_top: true,
subscribed: true,
+ is_recently_active: true,
};
add_row(RomeSub);
// dormant stream
@@ -596,11 +604,10 @@ test_ui("separators_only_pinned_and_dormant", ({override_rewire, mock_template})
color: "blue",
pin_to_top: false,
subscribed: true,
+ is_recently_active: false,
};
add_row(DenmarkSub);
- override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "Denmark");
-
let appended_elems;
$("#stream_filters").append = (elems) => {
appended_elems = elems;
diff --git a/web/tests/stream_list_sort.test.cjs b/web/tests/stream_list_sort.test.cjs
index ce9bff785a6..cd62656dbb5 100644
--- a/web/tests/stream_list_sort.test.cjs
+++ b/web/tests/stream_list_sort.test.cjs
@@ -7,9 +7,7 @@ const _ = require("lodash");
const {zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
-const people = zrequire("people");
const stream_data = zrequire("stream_data");
-const stream_topic_history = zrequire("stream_topic_history");
const stream_list_sort = zrequire("stream_list_sort");
const settings_config = zrequire("settings_config");
const {initialize_user_settings} = zrequire("user_settings");
@@ -17,57 +15,54 @@ const {initialize_user_settings} = zrequire("user_settings");
const user_settings = {};
initialize_user_settings({user_settings});
-function contains_sub(subs, sub) {
- return subs.some((s) => s.name === sub.name);
-}
-
-const me = {
- email: "[email protected]",
- full_name: "Current User",
- user_id: 100,
-};
-
const scalene = {
subscribed: true,
name: "scalene",
stream_id: 1,
pin_to_top: true,
+ is_recently_active: true,
};
const fast_tortoise = {
subscribed: true,
name: "fast tortoise",
stream_id: 2,
pin_to_top: false,
+ is_recently_active: true,
};
const pneumonia = {
subscribed: true,
name: "pneumonia",
stream_id: 3,
pin_to_top: false,
+ is_recently_active: false,
};
const clarinet = {
subscribed: true,
name: "clarinet",
stream_id: 4,
pin_to_top: false,
+ is_recently_active: true,
};
const weaving = {
subscribed: false,
name: "weaving",
stream_id: 5,
pin_to_top: false,
+ is_recently_active: true,
};
const stream_hyphen_underscore_slash_colon = {
subscribed: true,
name: "stream-hyphen_underscore/slash:colon",
stream_id: 6,
pin_to_top: false,
+ is_recently_active: true,
};
const muted_active = {
subscribed: true,
name: "muted active",
stream_id: 7,
pin_to_top: false,
+ is_recently_active: true,
is_muted: true,
};
const muted_pinned = {
@@ -75,6 +70,7 @@ const muted_pinned = {
name: "muted pinned",
stream_id: 8,
pin_to_top: true,
+ is_recently_active: true,
is_muted: true,
};
const archived = {
@@ -110,7 +106,7 @@ test("no_subscribed_streams", () => {
assert.equal(stream_list_sort.first_stream_id(), undefined);
});
-test("basics", ({override_rewire}) => {
+test("basics", () => {
stream_data.add_sub(scalene);
stream_data.add_sub(fast_tortoise);
stream_data.add_sub(pneumonia);
@@ -121,8 +117,6 @@ test("basics", ({override_rewire}) => {
stream_data.add_sub(muted_pinned);
stream_data.add_sub(archived);
- override_rewire(stream_list_sort, "has_recent_activity", (sub) => sub.name !== "pneumonia");
-
// Test sorting into categories/alphabetized
let sorted = sort_groups("");
assert.deepEqual(sorted.pinned_streams, [scalene.stream_id]);
@@ -207,109 +201,14 @@ test("basics", ({override_rewire}) => {
assert.deepEqual(sorted.dormant_streams, []);
});
-test("has_recent_activity", ({override}) => {
- people.init();
- people.add_active_user(me);
- people.initialize_current_user(me.user_id);
-
- let sub;
-
- override(
- user_settings,
- "demote_inactive_streams",
- settings_config.demote_inactive_streams_values.automatic.code,
- );
-
- stream_list_sort.set_filter_out_inactives();
-
- sub = {name: "pets", subscribed: false, stream_id: 111};
- stream_data.add_sub(sub);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_data.subscribe_myself(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.unsubscribed_subs(), sub));
-
- stream_data.unsubscribe_myself(sub);
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- sub.pin_to_top = true;
- assert.ok(stream_list_sort.has_recent_activity(sub));
- sub.pin_to_top = false;
-
- const opts = {
- stream_id: 222,
- message_id: 108,
- topic_name: "topic2",
- };
- stream_topic_history.add_message(opts);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- override(
- user_settings,
- "demote_inactive_streams",
- settings_config.demote_inactive_streams_values.always.code,
- );
-
- stream_list_sort.set_filter_out_inactives();
-
- sub = {name: "pets", subscribed: false, stream_id: 111};
- stream_data.add_sub(sub);
-
- assert.ok(!stream_list_sort.has_recent_activity(sub));
-
- sub.pin_to_top = true;
- assert.ok(stream_list_sort.has_recent_activity(sub));
- sub.pin_to_top = false;
-
- stream_data.subscribe_myself(sub);
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_data.unsubscribe_myself(sub);
- assert.ok(!stream_list_sort.has_recent_activity(sub));
-
- sub = {name: "lunch", subscribed: false, stream_id: 222};
- stream_data.add_sub(sub);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_topic_history.add_message(opts);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- override(
- user_settings,
- "demote_inactive_streams",
- settings_config.demote_inactive_streams_values.never.code,
- );
-
- stream_list_sort.set_filter_out_inactives();
-
- sub = {name: "pets", subscribed: false, stream_id: 111};
- stream_data.add_sub(sub);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_data.subscribe_myself(sub);
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_data.unsubscribe_myself(sub);
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- sub.pin_to_top = true;
- assert.ok(stream_list_sort.has_recent_activity(sub));
-
- stream_topic_history.add_message(opts);
-
- assert.ok(stream_list_sort.has_recent_activity(sub));
-});
-
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,
+ is_recently_active: true,
+ };
stream_data.add_sub(sub);
assert.ok(stream_list_sort.has_recent_activity_but_muted(sub));
});
diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs
index 76a86ef512c..99d399d4d23 100644
--- a/web/tests/typeahead_helper.test.cjs
+++ b/web/tests/typeahead_helper.test.cjs
@@ -2,11 +2,9 @@
const assert = require("node:assert/strict");
-const {mock_esm, zrequire} = require("./lib/namespace.cjs");
+const {zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
-const stream_topic_history = mock_esm("../src/stream_topic_history");
-
const settings_config = zrequire("settings_config");
const pm_conversations = zrequire("pm_conversations");
@@ -199,6 +197,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 0,
subscribed: true,
is_muted: false,
+ is_recently_active: true,
},
{
stream_id: 102,
@@ -207,6 +206,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 100,
subscribed: true,
is_muted: false,
+ is_recently_active: true,
},
{
stream_id: 103,
@@ -215,6 +215,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 0,
subscribed: true,
is_muted: true,
+ is_recently_active: true,
},
{
stream_id: 104,
@@ -223,6 +224,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 100,
subscribed: true,
is_muted: false,
+ is_recently_active: true,
},
{
stream_id: 105,
@@ -231,6 +233,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 0,
subscribed: true,
is_muted: false,
+ is_recently_active: false,
},
{
stream_id: 106,
@@ -239,6 +242,7 @@ test("sort_streams", ({override, override_rewire}) => {
stream_weekly_traffic: 2,
subscribed: true,
is_muted: false,
+ is_recently_active: true,
},
];
@@ -249,11 +253,6 @@ test("sort_streams", ({override, override_rewire}) => {
);
stream_list_sort.set_filter_out_inactives();
- override(
- stream_topic_history,
- "stream_has_topics",
- (stream_id) => ![105, 205].includes(stream_id),
- );
override_rewire(compose_state, "stream_name", () => "Dev");
test_streams = th.sort_streams(test_streams, "d");
@@ -281,30 +280,35 @@ test("sort_streams", ({override, override_rewire}) => {
name: "Dev",
description: "development help",
subscribed: true,
+ is_recently_active: true,
},
{
stream_id: 202,
name: "Docs",
description: "writing docs",
subscribed: true,
+ is_recently_active: true,
},
{
stream_id: 203,
name: "Derp",
description: "derping around",
subscribed: true,
+ is_recently_active: true,
},
{
stream_id: 204,
name: "Denmark",
description: "visiting Denmark",
subscribed: true,
+ is_recently_active: true,
},
{
stream_id: 205,
name: "dead",
description: "dead stream",
subscribed: true,
+ is_recently_active: false,
},
];