From 373c8a0bb509ee4f8c3c04410d9ff11fff8ae6e9 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 25 Jan 2017 07:23:22 -0800 Subject: [PATCH] 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. --- frontend_tests/node_tests/stream_list.js | 10 ++++++++-- frontend_tests/node_tests/user_events.js | 4 ++++ static/js/message_store.js | 1 - static/js/people.js | 19 +++++++++++++++++++ static/js/pm_list.js | 2 +- static/js/user_events.js | 1 + 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index 01a189a882..307fb7ea9c 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -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() { diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index b10cbc909b..8bd5c6490b 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -19,6 +19,10 @@ set_global('page_params', { is_admin: true, }); +set_global('pm_list', { + update_private_messages: function () {}, +}); + set_global('message_live_update', { }); diff --git a/static/js/message_store.js b/static/js/message_store.js index 72634af4d5..8f4fe1f8b7 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -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); diff --git a/static/js/people.js b/static/js/people.js index 27353054e6..7951ca34b8 100644 --- a/static/js/people.js +++ b/static/js/people.js @@ -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); diff --git a/static/js/pm_list.js b/static/js/pm_list.js index c5d43e84a4..277406a302 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -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); diff --git a/static/js/user_events.js b/static/js/user_events.js index ed03938802..237b5d94c0 100644 --- a/static/js/user_events.js +++ b/static/js/user_events.js @@ -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')) {