mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
compose pill: Add has_unconverted_data() helper.
This commit is contained in:
@@ -152,3 +152,32 @@ run_test('pills', () => {
|
||||
assert(appendValue_called);
|
||||
assert(text_cleared);
|
||||
});
|
||||
|
||||
run_test('has_unconverted_data', () => {
|
||||
compose_pm_pill.widget = {
|
||||
is_pending: () => true,
|
||||
};
|
||||
|
||||
// If the pill itself has pending data, we have unconverted
|
||||
// data.
|
||||
assert.equal(compose_pm_pill.has_unconverted_data(), true);
|
||||
|
||||
compose_pm_pill.widget = {
|
||||
is_pending: () => false,
|
||||
items: () => [{user_id: 99}],
|
||||
};
|
||||
|
||||
// Our pill is complete and all items containt user_id, so
|
||||
// we do NOT have unconverted data.
|
||||
assert.equal(compose_pm_pill.has_unconverted_data(), false);
|
||||
|
||||
compose_pm_pill.widget = {
|
||||
is_pending: () => false,
|
||||
items: () => [{user_id: 99}, {email: 'random@mit.edu'}],
|
||||
};
|
||||
|
||||
// One of our items only knows email (as in a bridge-with-zephyr
|
||||
// scenario where we might not have registered the user yet), so
|
||||
// we have some unconverted data.
|
||||
assert.equal(compose_pm_pill.has_unconverted_data(), true);
|
||||
});
|
||||
|
||||
@@ -41,6 +41,10 @@ exports.get_user_ids = function () {
|
||||
return user_pill.get_user_ids(exports.widget);
|
||||
};
|
||||
|
||||
exports.has_unconverted_data = function () {
|
||||
return user_pill.has_unconverted_data(exports.widget);
|
||||
};
|
||||
|
||||
exports.get_user_ids_string = function () {
|
||||
var user_ids = exports.get_user_ids();
|
||||
var sorted_user_ids = util.sorted_ids(user_ids);
|
||||
|
||||
@@ -76,6 +76,21 @@ exports.get_user_ids = function (pill_widget) {
|
||||
return user_ids;
|
||||
};
|
||||
|
||||
exports.has_unconverted_data = function (pill_widget) {
|
||||
// This returns true if we either have text that hasn't been
|
||||
// turned into pills or email-only pills (for Zephyr).
|
||||
if (pill_widget.is_pending()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var items = pill_widget.items();
|
||||
var has_unknown_items = _.any(items, function (item) {
|
||||
return item.user_id === undefined;
|
||||
});
|
||||
|
||||
return has_unknown_items;
|
||||
};
|
||||
|
||||
exports.typeahead_source = function (pill_widget) {
|
||||
var items = people.get_realm_persons();
|
||||
var taken_user_ids = exports.get_user_ids(pill_widget);
|
||||
|
||||
Reference in New Issue
Block a user