Maintain a list of people in the realm.

people_list and people_dict include the feedback bot and anyone you've
cross-realm PM'd with. Useful for autocomplete, but not for admin and
stream settings views.

Fixes the UI part of Trac #1772.

(imported from commit cdefd4e86980447aad5190e7fc8ae3666d66e3c3)
This commit is contained in:
Kevin Mehall 2013-09-05 18:19:15 -04:00
parent 45b14a0c96
commit 810dd89621
4 changed files with 21 additions and 10 deletions

View File

@ -9,7 +9,7 @@ function populate_users () {
return a.full_name.toLowerCase().localeCompare(b.full_name.toLowerCase()); return a.full_name.toLowerCase().localeCompare(b.full_name.toLowerCase());
}); });
$.each(page_params.people_list, function (index, person) { realm_people_dict.each(function (person, key) {
if (!person.is_bot) { if (!person.is_bot) {
tb.append(templates.render("admin_user_list", {person: person})); tb.append(templates.render("admin_user_list", {person: person}));
} }

View File

@ -599,12 +599,8 @@ function update_announce_stream_state() {
function show_new_stream_modal() { function show_new_stream_modal() {
var people_minus_you_and_internal_users = []; var people_minus_you_and_internal_users = [];
_.each(page_params.people_list, function (person) { realm_people_dict.each(function (person) {
if (person.email !== page_params.email && if (person.email !== page_params.email) {
(page_params.domain === "zulip.com" ||
person.email.split('@')[1] !== "zulip.com"
)
) {
people_minus_you_and_internal_users.push({"email": person.email, people_minus_you_and_internal_users.push({"email": person.email,
"full_name": person.full_name}); "full_name": person.full_name});
} }

View File

@ -5,7 +5,13 @@ var home_msg_list = new MessageList('zhome',
); );
var narrowed_msg_list; var narrowed_msg_list;
var current_msg_list = home_msg_list; var current_msg_list = home_msg_list;
// The following two Dicts point to the same objects
// All people we've seen
var people_dict = new Dict(); var people_dict = new Dict();
// People in this realm
var realm_people_dict = new Dict();
var recent_subjects = new Dict({fold_case: true}); var recent_subjects = new Dict({fold_case: true});
var queued_mark_as_read = []; var queued_mark_as_read = [];
@ -39,12 +45,17 @@ var events_stored_during_tutorial = [];
var waiting_on_browser_scroll = true; var waiting_on_browser_scroll = true;
function add_person(person) { function add_person(person, in_realm) {
page_params.people_list.push(person); page_params.people_list.push(person);
people_dict.set(person.email, person); people_dict.set(person.email, person);
person.pm_recipient_count = 0; person.pm_recipient_count = 0;
} }
function add_person_in_realm(person) {
realm_people_dict.set(person.email, person);
add_person(person);
}
function remove_person(person) { function remove_person(person) {
var i; var i;
for (i = 0; i < page_params.people_list.length; i++) { for (i = 0; i < page_params.people_list.length; i++) {
@ -54,6 +65,7 @@ function remove_person(person) {
} }
} }
people_dict.del(person.email); people_dict.del(person.email);
realm_people_dict.del(person.email);
} }
function update_person(person) { function update_person(person) {
@ -68,6 +80,8 @@ function update_person(person) {
return; return;
} }
people_dict.get(person.email).full_name = person.full_name; people_dict.get(person.email).full_name = person.full_name;
// This should be the same object, but...
realm_people_dict.get(person.email).full_name = person.full_name;
for (i = 0; i < page_params.people_list.length; i++) { for (i = 0; i < page_params.people_list.length; i++) {
if (page_params.people_list[i].email === person.email) { if (page_params.people_list[i].email === person.email) {
page_params.people_list[i].full_name = person.full_name; page_params.people_list[i].full_name = person.full_name;
@ -821,7 +835,7 @@ function get_updates_success(data) {
break; break;
case 'realm_user': case 'realm_user':
if (event.op === 'add') { if (event.op === 'add') {
add_person(event.person); add_person_in_realm(event.person);
} else if (event.op === 'remove') { } else if (event.op === 'remove') {
remove_person(event.person); remove_person(event.person);
} else if (event.op === 'update') { } else if (event.op === 'update') {
@ -1228,6 +1242,7 @@ function consider_bankruptcy() {
_.each(page_params.people_list, function (person) { _.each(page_params.people_list, function (person) {
people_dict.set(person.email, person); people_dict.set(person.email, person);
realm_people_dict.set(person.email, person);
person.pm_recipient_count = 0; person.pm_recipient_count = 0;
}); });

View File

@ -44,7 +44,7 @@ var globals =
// zulip.js // zulip.js
+ ' all_msg_list home_msg_list narrowed_msg_list current_msg_list get_updates_params' + ' all_msg_list home_msg_list narrowed_msg_list current_msg_list get_updates_params'
+ ' add_messages' + ' add_messages'
+ ' people_dict' + ' people_dict realm_people_dict'
+ ' keep_pointer_in_view' + ' keep_pointer_in_view'
+ ' respond_to_message recenter_view last_viewport_movement_direction' + ' respond_to_message recenter_view last_viewport_movement_direction'
+ ' scroll_to_selected get_private_message_recipient' + ' scroll_to_selected get_private_message_recipient'