Skip to content

Commit

Permalink
Sort User List to bring starred users at top.
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikmaji committed Jun 7, 2016
1 parent 4f9d2fe commit ddd1c9b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
15 changes: 10 additions & 5 deletions frontend_tests/node_tests/presence_list_performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,36 @@ activity.presence_info = {
num_unread: 0,
type: 'active',
type_desc: 'is active',
mobile: undefined },
mobile: undefined,
starred: false },
{ name: 'Jill Hill',
email: 'jill@zulip.com',
num_unread: 0,
type: 'active',
type_desc: 'is active',
mobile: undefined },
mobile: undefined,
starred: false },
{ name: 'Norbert Oswald',
email: 'norbert@zulip.com',
num_unread: 0,
type: 'active',
type_desc: 'is active',
mobile: undefined },
mobile: undefined,
starred: false },
{ name: 'Alice Smith',
email: 'alice@zulip.com',
num_unread: 0,
type: 'idle',
type_desc: 'is not active',
mobile: undefined },
mobile: undefined,
starred: false },
{ name: 'Marky Mark',
email: 'mark@zulip.com',
num_unread: 0,
type: 'idle',
type_desc: 'is not active',
mobile: undefined }
mobile: undefined,
starred: false }
]);
}());

Expand Down
15 changes: 14 additions & 1 deletion static/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,21 @@ exports.update_users = function (user_list) {
};
}

var user_info = _.map(users, info_for);
function filter_starred_user(user) {
if (user.starred === true) {
return user;
}
}

// User info unsorted
var user_info_unsorted = _.map(users, info_for);

// Filtering out starred and unstarred users out of all users info
var starred_users = _.filter(user_info_unsorted, filter_starred_user);
var unstarred_users = _.difference(user_info_unsorted, starred_users);

// Concatenating starred users with unstarred users to get starred users on top
var user_info = starred_users.concat(unstarred_users);
if (user_list !== undefined) {
// Render right panel partially
$.each(user_info, function (index, user) {
Expand Down
3 changes: 3 additions & 0 deletions static/js/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ exports.get_by_email = function get_by_email(email) {
};

exports.get_star_status = function get_star_status(email) {
if (page_params.starred_users === undefined) {
return false;
}
return page_params.starred_users.indexOf(email)>=0;
};

Expand Down
4 changes: 2 additions & 2 deletions static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,9 @@ exports.star_unstar_user = function (email) {
success: function (result) {
var user_index = page_params.starred_users.indexOf(result.email);
if (user_index >= 0) {
page_params.starred_users.splice(user_index, 1);
page_params.starred_users.splice(user_index, 1);
} else {
page_params.starred_users.push(result.email);
page_params.starred_users.push(result.email);
}
activity.update_users();
}
Expand Down

0 comments on commit ddd1c9b

Please sign in to comment.