mirror of https://github.com/zulip/zulip.git
Break typeahead_helper's dependency on compose.js.
We now have typeahead_helper's callers pass in compose.stream() when it's needed for sorting purposes.
This commit is contained in:
parent
166f149ef9
commit
7b1bfd6703
|
@ -2,7 +2,6 @@ var th = require('js/typeahead_helper.js');
|
|||
|
||||
global.stub_out_jquery();
|
||||
|
||||
set_global('compose', {});
|
||||
set_global('page_params', {is_zephyr_mirror_realm: false});
|
||||
|
||||
add_dependencies({
|
||||
|
@ -60,15 +59,18 @@ _.each(matches, function (person) {
|
|||
});
|
||||
|
||||
(function test_sort_recipients() {
|
||||
function get_typeahead_result(query) {
|
||||
var result = th.sort_recipients(global.people.get_realm_persons(), query);
|
||||
function get_typeahead_result(query, current_stream) {
|
||||
var result = th.sort_recipients(
|
||||
global.people.get_realm_persons(),
|
||||
query,
|
||||
current_stream
|
||||
);
|
||||
return _.map(result, function (person) {
|
||||
return person.email;
|
||||
});
|
||||
}
|
||||
|
||||
global.compose.stream_name = function () { return ""; };
|
||||
assert.deepEqual(get_typeahead_result("b"), [
|
||||
assert.deepEqual(get_typeahead_result("b", ""), [
|
||||
'b_user_1@zulip.net',
|
||||
'b_user_2@zulip.net',
|
||||
'b_bot@example.com',
|
||||
|
@ -77,10 +79,9 @@ _.each(matches, function (person) {
|
|||
'a_bot@zulip.com',
|
||||
]);
|
||||
|
||||
global.compose.stream_name = function () { return "Dev"; };
|
||||
var subscriber_email = "b_user_2@zulip.net";
|
||||
stream_data.add_subscriber("Dev", people.get_user_id(subscriber_email));
|
||||
assert.deepEqual(get_typeahead_result("b"), [
|
||||
assert.deepEqual(get_typeahead_result("b", "Dev"), [
|
||||
subscriber_email,
|
||||
'b_user_1@zulip.net',
|
||||
'b_bot@example.com',
|
||||
|
@ -90,8 +91,7 @@ _.each(matches, function (person) {
|
|||
]);
|
||||
|
||||
// No match
|
||||
global.compose.stream_name = function () { return "Linux"; };
|
||||
assert.deepEqual(get_typeahead_result("h"), [
|
||||
assert.deepEqual(get_typeahead_result("h", "Linux"), [
|
||||
'a_user@zulip.org',
|
||||
'b_user_1@zulip.net',
|
||||
'b_user_2@zulip.net',
|
||||
|
|
|
@ -369,7 +369,7 @@ exports.initialize_compose_typeahead = function (selector, completions) {
|
|||
if (this.completing === 'emoji') {
|
||||
return typeahead_helper.sort_emojis(matches, this.token);
|
||||
} else if (this.completing === 'mention') {
|
||||
return typeahead_helper.sort_recipients(matches, this.token);
|
||||
return typeahead_helper.sort_recipients(matches, this.token, compose.stream_name());
|
||||
} else if (this.completing === 'stream') {
|
||||
return typeahead_helper.sort_streams(matches, this.token);
|
||||
}
|
||||
|
@ -477,7 +477,11 @@ exports.initialize = function () {
|
|||
|
||||
return query_matches_person(current_recipient, item);
|
||||
},
|
||||
sorter: typeahead_helper.sort_recipientbox_typeahead,
|
||||
sorter: function (matches) {
|
||||
var current_stream = compose.stream_name();
|
||||
return typeahead_helper.sort_recipientbox_typeahead(
|
||||
this.query, matches, current_stream);
|
||||
},
|
||||
updater: function (item, event) {
|
||||
var previous_recipients = exports.get_cleaned_pm_recipients(this.query);
|
||||
previous_recipients.pop();
|
||||
|
|
|
@ -397,7 +397,11 @@ function show_subscription_settings(sub_row) {
|
|||
return (item.email.toLowerCase().indexOf(query) !== -1) ||
|
||||
(item.full_name.toLowerCase().indexOf(query) !== -1);
|
||||
},
|
||||
sorter: typeahead_helper.sort_recipientbox_typeahead,
|
||||
sorter: function (matches) {
|
||||
var current_stream = compose.stream_name();
|
||||
return typeahead_helper.sort_recipientbox_typeahead(
|
||||
this.query, matches, current_stream);
|
||||
},
|
||||
updater: function (item) {
|
||||
return item.email;
|
||||
},
|
||||
|
|
|
@ -171,12 +171,10 @@ exports.sort_for_at_mentioning = function (objs, current_stream) {
|
|||
return subs_sorted.concat(non_subs_sorted);
|
||||
};
|
||||
|
||||
exports.sort_recipients = function (matches, query) {
|
||||
exports.sort_recipients = function (matches, query, current_stream) {
|
||||
var name_results = prefix_sort(query, matches, function (x) { return x.full_name; });
|
||||
var email_results = prefix_sort(query, name_results.rest, function (x) { return x.email; });
|
||||
|
||||
var current_stream = compose.stream_name();
|
||||
|
||||
var matches_sorted = exports.sort_for_at_mentioning(
|
||||
name_results.matches.concat(email_results.matches),
|
||||
current_stream
|
||||
|
@ -213,11 +211,11 @@ exports.sort_streams = function (matches, query) {
|
|||
return name_results.matches.concat(desc_results.matches.concat(desc_results.rest));
|
||||
};
|
||||
|
||||
exports.sort_recipientbox_typeahead = function (matches) {
|
||||
exports.sort_recipientbox_typeahead = function (query, matches, current_stream) {
|
||||
// input_text may be one or more pm recipients
|
||||
var cleaned = composebox_typeahead.get_cleaned_pm_recipients(this.query);
|
||||
var query = cleaned[cleaned.length - 1];
|
||||
return exports.sort_recipients(matches, query);
|
||||
var cleaned = composebox_typeahead.get_cleaned_pm_recipients(query);
|
||||
query = cleaned[cleaned.length - 1];
|
||||
return exports.sort_recipients(matches, query, current_stream);
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
|
Loading…
Reference in New Issue