buddy list: Make Group PMs appear more quickly.

It used to be the case that you would get new messages for a
huddle, but the huddle wouldn't show up on your buddy list until
the every-50-seconds mass update of the buddy list.

Now we make sure to work with non-stale jQuery objects, and,
more importantly, we resize ourselves if we add new huddles.

(The resize issue arises due to some complicated heuristics
where we don't want group PMs to take up too much of the buddy
list for users who don't have many in their history.)
This commit is contained in:
Steve Howell
2016-11-11 10:30:04 -08:00
parent 197edcca0e
commit 06f4857221
2 changed files with 21 additions and 4 deletions

View File

@@ -9,6 +9,10 @@ add_dependencies({
people: 'js/people.js'
});
set_global('resize', {
resize_page_components: function () {}
});
set_global('document', {
hasFocus: function () {
return true;

View File

@@ -53,6 +53,8 @@ var huddle_timestamps = new Dict();
exports.process_loaded_messages = function (messages) {
var need_resize = false;
_.each(messages, function (message) {
if (message.type === 'private') {
if (message.reply_to.indexOf(',') > 0) {
@@ -60,12 +62,17 @@ exports.process_loaded_messages = function (messages) {
if (!old_timestamp || (old_timestamp < message.timestamp)) {
huddle_timestamps.set(message.reply_to, message.timestamp);
need_resize = true;
}
}
}
});
exports.update_huddles();
if (need_resize) {
resize.resize_page_components(); // big hammer
}
};
exports.get_huddles = function () {
@@ -279,17 +286,23 @@ function actually_update_users_for_search() {
var update_users_for_search = _.throttle(actually_update_users_for_search, 50);
function show_huddles () {
$('#group-pm-list').expectOne().show();
}
function hide_huddles () {
$('#group-pm-list').expectOne().hide();
}
exports.update_huddles = function () {
if (page_params.presence_disabled) {
return;
}
var section = $('#group-pm-list').expectOne();
var huddles = exports.get_huddles().slice(0, 10);
if (huddles.length === 0) {
section.hide();
hide_huddles();
return;
}
@@ -310,7 +323,7 @@ exports.update_huddles = function () {
stream_list.set_presence_list_count(huddle, count);
});
section.show();
show_huddles();
};
function status_from_timestamp(baseline_time, presence) {