Live-update PM list for full-name changes.

We now trigger an event in user_events.js, and we dynamically
build the list of names in pm_list.js by calling out to
people.get_recipients().

We have a few variations of functions that build lists of names
for huddles, which should be cleaned up eventually.  They are
called at different times in the code path, so the different
functions, while doing mostly the same thing, start with different
data sources.
This commit is contained in:
Steve Howell
2017-01-25 07:23:22 -08:00
committed by showell
parent f836ae0dfb
commit 373c8a0bb5
6 changed files with 33 additions and 4 deletions

View File

@@ -44,8 +44,15 @@ var bob = {
user_id: 102,
full_name: 'Bob',
};
var me = {
email: 'me@zulip.com',
user_id: 103,
full_name: 'Me Myself',
};
global.people.add_in_realm(alice);
global.people.add_in_realm(bob);
global.people.add_in_realm(me);
global.people.initialize_current_user(me.user_id);
(function test_build_private_messages_list() {
var active_conversation = "alice@zulip.com,bob@zulip.com";
@@ -53,7 +60,6 @@ global.people.add_in_realm(bob);
var conversations = {user_ids_string: '101,102',
display_reply_to: active_conversation,
timestamp: 0 };
global.message_store.recent_private_messages.push(conversations);
@@ -65,7 +71,7 @@ global.people.add_in_realm(bob);
global.write_test_output("test_build_private_messages_list", convos_html);
var conversation = $(convos_html).find('a').text().trim();
assert.equal(conversation, active_conversation);
assert.equal(conversation, 'Alice, Bob');
}());
function clear_filters() {

View File

@@ -19,6 +19,10 @@ set_global('page_params', {
is_admin: true,
});
set_global('pm_list', {
update_private_messages: function () {},
});
set_global('message_live_update', {
});

View File

@@ -80,7 +80,6 @@ exports.process_message_for_recent_private_messages =
});
var new_conversation = {user_ids_string: user_ids_string,
display_reply_to: message.display_reply_to,
timestamp: Math.max(message.timestamp, current_timestamp)};
exports.recent_private_messages.push(new_conversation);

View File

@@ -96,6 +96,25 @@ exports.emails_strings_to_user_ids_string = function (emails_string) {
return user_ids.join(',');
};
exports.get_full_name = function (user_id) {
return people_by_user_id_dict.get(user_id).full_name;
};
exports.get_recipients = function (user_ids_string) {
// See message_store.get_pm_full_names() for a similar function.
var user_ids = user_ids_string.split(',');
var other_ids = _.reject(user_ids, exports.is_my_user_id);
if (other_ids.length === 0) {
// private message with oneself
return exports.my_full_name();
}
var names = _.map(other_ids, exports.get_full_name).sort();
return names.join(', ');
};
exports.emails_to_slug = function (emails_string) {
var slug = exports.emails_strings_to_user_ids_string(emails_string);

View File

@@ -92,9 +92,9 @@ exports._build_private_messages_list = function (active_conversation, max_privat
}
_.each(private_messages, function (private_message_obj, idx) {
var recipients_string = private_message_obj.display_reply_to;
var user_ids_string = private_message_obj.user_ids_string;
var reply_to = people.user_ids_string_to_emails_string(user_ids_string);
var recipients_string = people.get_recipients(user_ids_string);
var num_unread = unread.num_unread_for_person(user_ids_string);

View File

@@ -22,6 +22,7 @@ exports.update_person = function update(person) {
admin.update_user_full_name(person.email, person.full_name);
activity.redraw();
message_live_update.update_user_full_name(person.user_id, person.full_name);
pm_list.update_private_messages();
}
if (_.has(person, 'is_admin')) {