mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
activity.js: Extract get_filtered_and_sorted_user_ids().
This function was extracted from build_user_sidebar(). We also slightly streamlined it to not unnecessarily call filter() when the filter text was blank. This extraction also eliminated the need for us to have the two-line filter_and_sort() function. Also, we get to 100% coverage in this commit.
This commit is contained in:
@@ -250,6 +250,7 @@ presence.presence_info[jill.user_id] = { status: activity.ACTIVE };
|
|||||||
presence.presence_info[mark.user_id] = { status: activity.IDLE };
|
presence.presence_info[mark.user_id] = { status: activity.IDLE };
|
||||||
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
presence.presence_info[norbert.user_id] = { status: activity.ACTIVE };
|
||||||
presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
|
presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
|
||||||
|
presence.presence_info[me.user_id] = { status: activity.ACTIVE };
|
||||||
|
|
||||||
activity.set_user_list_filter();
|
activity.set_user_list_filter();
|
||||||
|
|
||||||
@@ -407,33 +408,42 @@ presence.presence_info[zoe.user_id] = { status: activity.ACTIVE };
|
|||||||
var user_filter = $('.user-list-filter');
|
var user_filter = $('.user-list-filter');
|
||||||
user_filter.val(''); // no search filter
|
user_filter.val(''); // no search filter
|
||||||
|
|
||||||
var user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
activity.set_user_list_filter();
|
||||||
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
|
||||||
|
var user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
|
assert.deepEqual(user_ids, [
|
||||||
|
alice.user_id,
|
||||||
|
fred.user_id,
|
||||||
|
jill.user_id,
|
||||||
|
norbert.user_id,
|
||||||
|
zoe.user_id,
|
||||||
|
mark.user_id,
|
||||||
|
]);
|
||||||
|
|
||||||
user_filter.val('abc'); // no match
|
user_filter.val('abc'); // no match
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, []);
|
assert.deepEqual(user_ids, []);
|
||||||
|
|
||||||
user_filter.val('fred'); // match fred
|
user_filter.val('fred'); // match fred
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, [fred.user_id]);
|
assert.deepEqual(user_ids, [fred.user_id]);
|
||||||
|
|
||||||
user_filter.val('fred,alice'); // match fred and alice
|
user_filter.val('fred,alice'); // match fred and alice
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
||||||
|
|
||||||
user_filter.val('fr,al'); // match fred and alice partials
|
user_filter.val('fr,al'); // match fred and alice partials
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
||||||
|
|
||||||
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
presence.presence_info[alice.user_id] = { status: activity.IDLE };
|
||||||
user_filter.val('fr,al'); // match fred and alice partials and idle user
|
user_filter.val('fr,al'); // match fred and alice partials and idle user
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, [fred.user_id, alice.user_id]);
|
assert.deepEqual(user_ids, [fred.user_id, alice.user_id]);
|
||||||
|
|
||||||
$.stub_selector('.user-list-filter', []);
|
$.stub_selector('.user-list-filter', []);
|
||||||
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
|
presence.presence_info[alice.user_id] = { status: activity.ACTIVE };
|
||||||
user_ids = activity._filter_and_sort([alice.user_id, fred.user_id]);
|
user_ids = activity.get_filtered_and_sorted_user_ids();
|
||||||
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
assert.deepEqual(user_ids, [alice.user_id, fred.user_id]);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -269,14 +269,6 @@ function matches_filter(user_id) {
|
|||||||
return (filter_user_ids([user_id]).length === 1);
|
return (filter_user_ids([user_id]).length === 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function filter_and_sort(user_ids) {
|
|
||||||
user_ids = filter_user_ids(user_ids);
|
|
||||||
user_ids = sort_users(user_ids);
|
|
||||||
return user_ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports._filter_and_sort = filter_and_sort;
|
|
||||||
|
|
||||||
function get_num_unread(user_id) {
|
function get_num_unread(user_id) {
|
||||||
if (unread.suppress_unread_counts) {
|
if (unread.suppress_unread_counts) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -345,15 +337,7 @@ exports.build_user_sidebar = function () {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user_ids;
|
var user_ids = exports.get_filtered_and_sorted_user_ids();
|
||||||
|
|
||||||
if (exports.get_filter_text()) {
|
|
||||||
// If there's a filter, select from all users, not just those
|
|
||||||
// recently active.
|
|
||||||
user_ids = filter_and_sort(people.get_realm_human_user_ids());
|
|
||||||
} else {
|
|
||||||
user_ids = filter_and_sort(presence.get_user_ids());
|
|
||||||
}
|
|
||||||
|
|
||||||
var user_info = _.map(user_ids, info_for).filter(function (person) {
|
var user_info = _.map(user_ids, info_for).filter(function (person) {
|
||||||
// filtered bots and yourself are set to "undefined" in the `info_for`
|
// filtered bots and yourself are set to "undefined" in the `info_for`
|
||||||
@@ -593,6 +577,23 @@ function focus_user_filter(e) {
|
|||||||
update_clear_search_button();
|
update_clear_search_button();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.get_filtered_and_sorted_user_ids = function () {
|
||||||
|
var user_ids;
|
||||||
|
|
||||||
|
if (exports.get_filter_text()) {
|
||||||
|
// If there's a filter, select from all users, not just those
|
||||||
|
// recently active.
|
||||||
|
user_ids = filter_user_ids(people.get_realm_human_user_ids());
|
||||||
|
} else {
|
||||||
|
// From large realms, the user_ids in presence may exclude
|
||||||
|
// users who have been idle more than three weeks. When the
|
||||||
|
// filter text is blank, we show only those recently active users.
|
||||||
|
user_ids = presence.get_user_ids();
|
||||||
|
}
|
||||||
|
|
||||||
|
return sort_users(user_ids);
|
||||||
|
};
|
||||||
|
|
||||||
exports.set_user_list_filter = function () {
|
exports.set_user_list_filter = function () {
|
||||||
meta.$user_list_filter = $(".user-list-filter");
|
meta.$user_list_filter = $(".user-list-filter");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ USAGE = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
enforce_fully_covered = {
|
enforce_fully_covered = {
|
||||||
# activity.js Removed while we debug some coverage issues
|
'static/js/activity.js',
|
||||||
# 'static/js/activity.js',
|
|
||||||
'static/js/alert_words.js',
|
'static/js/alert_words.js',
|
||||||
'static/js/bot_data.js',
|
'static/js/bot_data.js',
|
||||||
'static/js/channel.js',
|
'static/js/channel.js',
|
||||||
|
|||||||
Reference in New Issue
Block a user