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: Add message view context to PM recipient suggestions.

N-Shar-ma963e1412b590
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js
index 403c7819cb6..57563cbb4c5 100644
--- a/frontend_tests/node_tests/composebox_typeahead.js
+++ b/frontend_tests/node_tests/composebox_typeahead.js
@@ -1706,3 +1706,29 @@ test("muted users excluded from results", () => {
const mention_all = ct.broadcast_mentions()[0];
assert.deepEqual(results, [mention_all, call_center]);
});
+
+test("PM recipients sorted according to stream / topic being viewed", ({override_rewire}) => {
+ // This tests that PM recipient results are sorted with subscribers of
+ // the stream / topic being viewed being given priority. If no stream
+ // is being viewed, the sort is alphabetical (for testing, since we do not
+ // simulate PM history)
+ let results;
+
+ // Simulating just cordelia being subscribed to denmark.
+ override_rewire(
+ stream_data,
+ "is_user_subscribed",
+ (stream_id, user_id) =>
+ stream_id === denmark_stream.stream_id && user_id === cordelia.user_id,
+ );
+
+ // When viewing no stream, sorting is alphabetical
+ compose_state.set_stream_name("");
+ results = ct.get_pm_people("li");
+ assert.deepEqual(results, [alice, cordelia]);
+
+ // When viewing denmark stream, subscriber twin2 is placed higher
+ compose_state.set_stream_name("Denmark");
+ results = ct.get_pm_people("li");
+ assert.deepEqual(results, [cordelia, alice]);
+});
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 85f8dc75cd4..b53c389103c 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -445,6 +445,8 @@ export function get_pm_people(query) {
const opts = {
want_broadcast: false,
filter_pills: true,
+ stream: compose_state.stream_name(),
+ topic: compose_state.topic(),
};
return get_person_suggestions(query, opts);
}
diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js
index b9a22e27317..af615e69086 100644
--- a/static/js/typeahead_helper.js
+++ b/static/js/typeahead_helper.js
@@ -234,7 +234,7 @@ export function compare_people_for_relevance(
}
export function sort_people_for_relevance(objs, current_stream_name, current_topic) {
- // If sorting for recipientbox typeahead or compose state is private, then current_stream = ""
+ // If sorting for recipientbox typeahead and not viewing a stream / topic, then current_stream = ""
let current_stream = false;
if (current_stream_name) {
current_stream = stream_data.get_sub(current_stream_name);