Files
zulip/static/js/buddy_list.js
Steve Howell 76d83af62b buddy list: Extract activity.narrow_for_user.
This change makes a common code path for these two operations:
        * clicking on a user
        * hitting enter when a user is highlighted

The newer codepath, for the enter key, had some differences that
were just confusing.  For example, there's no need to open the
compose box, since that's already handled by the narrowing code.

For possibly dubious reasons, I let each handler still call
popovers.hide_all() on its own, since it makes the code a bit
more consistent with existing code patterns.
2018-04-22 20:08:08 -07:00

56 lines
1.4 KiB
JavaScript

var buddy_list = (function () {
var self = {};
self.populate = function (opts) {
var user_info = opts.items;
var html = templates.render('user_presence_rows', {users: user_info});
$('#user_presences').html(html);
};
self.find_li = function (opts) {
var user_id = opts.key;
return $("li.user_sidebar_entry[data-user-id='" + user_id + "']");
};
self.get_key_from_li = function (opts) {
var user_id = opts.li.expectOne().attr('data-user-id');
return user_id;
};
self.insert_or_move = function (opts) {
var user_id = opts.key;
var info = opts.item;
var compare_function = opts.compare_function;
$('#user_presences').find('[data-user-id="' + user_id + '"]').remove();
var html = templates.render('user_presence_row', info);
var items = $('#user_presences li').toArray();
function insert() {
var i = 0;
for (i = 0; i < items.length; i += 1) {
var li = $(items[i]);
var list_user_id = li.attr('data-user-id');
if (compare_function(user_id, list_user_id) < 0) {
li.before(html);
return;
}
}
$('#user_presences').append(html);
}
insert();
};
return self;
}());
if (typeof module !== 'undefined') {
module.exports = buddy_list;
}