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.

typeahead: Improve channel sort priorities in sort_streams.

Evy Kassirer693c3347e477
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts
index a61db8fed94..46487739b56 100644
--- a/web/src/typeahead_helper.ts
+++ b/web/src/typeahead_helper.ts
@@ -1027,19 +1027,23 @@ export function compare_by_activity(
return diff;
}
- // Subscribed channels sort above unsubscribed ones, which aren't
- // ranked further by the criteria below.
+ // Archived channels sort below all unarchived channels, and within
+ // each of those groups subscribed channels sort above unsubscribed
+ // ones.
+ diff = prefer_true(!stream_a.is_archived, !stream_b.is_archived);
+ if (diff !== 0) {
+ return diff;
+ }
diff = prefer_true(stream_a.subscribed, stream_b.subscribed);
if (diff !== 0) {
return diff;
}
+
if (stream_a.subscribed) {
- // Prioritize unmuted channels, then pinned channels, then
- // recently active ones.
- diff = prefer_true(!stream_a.is_muted, !stream_b.is_muted);
- if (diff !== 0) {
- return diff;
- }
+ // Among subscribed channels of the same archived status, order
+ // them by the same priorities as the left sidebar: pinned, then
+ // recently active, then unmuted. Unsubscribed channels aren't
+ // ranked by these, falling through to the tiebreakers below.
diff = prefer_true(stream_a.pin_to_top, stream_b.pin_to_top);
if (diff !== 0) {
return diff;
@@ -1051,6 +1055,10 @@ export function compare_by_activity(
if (diff !== 0) {
return diff;
}
+ diff = prefer_true(!stream_a.is_muted, !stream_b.is_muted);
+ if (diff !== 0) {
+ return diff;
+ }
}
// Fall back to recent traffic, and then the channel name.
diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs
index d442bbffd46..e1f30d26bb5 100644
--- a/web/tests/typeahead_helper.test.cjs
+++ b/web/tests/typeahead_helper.test.cjs
@@ -280,10 +280,10 @@ test("sort_streams", ({override}) => {
test_streams = th.sort_streams(test_streams, "d");
assert.deepEqual(test_streams[0].name, "Dev"); // Stream being composed to
assert.deepEqual(test_streams[1].name, "Denmark"); // Pinned stream
- assert.deepEqual(test_streams[2].name, "Docs"); // Active stream
- assert.deepEqual(test_streams[3].name, "dead (almost)"); // Relatively inactive stream
- assert.deepEqual(test_streams[4].name, "dead"); // Completely inactive stream
- assert.deepEqual(test_streams[5].name, "Derp"); // Muted stream last
+ assert.deepEqual(test_streams[2].name, "Docs"); // Active stream, more traffic
+ assert.deepEqual(test_streams[3].name, "dead (almost)"); // Active stream, less traffic
+ assert.deepEqual(test_streams[4].name, "Derp"); // Active but muted stream
+ assert.deepEqual(test_streams[5].name, "dead"); // Inactive stream last
// Sort streams by name
test_streams = th.sort_streams_by_name(test_streams, "d");
@@ -411,6 +411,41 @@ test("sort_streams", ({override}) => {
test_streams = th.sort_streams(test_streams, "d");
assert.deepEqual(test_streams[0].name, "Dusk"); // More traffic
assert.deepEqual(test_streams[1].name, "Dawn"); // Less traffic
+
+ // Archived channels sort below all unarchived channels, and within
+ // each group subscribed channels sort above unsubscribed ones.
+ test_streams = [
+ {
+ stream_id: 403,
+ name: "archived and subscribed",
+ subscribed: true,
+ is_archived: true,
+ },
+ {
+ stream_id: 404,
+ name: "unarchived and subscribed",
+ subscribed: true,
+ is_archived: false,
+ },
+ {
+ stream_id: 405,
+ name: "archived and unsubscribed",
+ subscribed: false,
+ is_archived: true,
+ },
+ {
+ stream_id: 406,
+ name: "unarchived and unsubscribed",
+ subscribed: false,
+ is_archived: false,
+ },
+ ];
+
+ test_streams = th.sort_streams(test_streams, "and");
+ assert.deepEqual(test_streams[0].name, "unarchived and subscribed");
+ assert.deepEqual(test_streams[1].name, "unarchived and unsubscribed");
+ assert.deepEqual(test_streams[2].name, "archived and subscribed");
+ assert.deepEqual(test_streams[3].name, "archived and unsubscribed");
});
function language_items(languages) {