Eliminate people.reify() and mostly ignore unknown users.

If I try to send a message to an unknown user (which is possible
for some types of realms), then I simply ignore them during the
send codepath, so that I don't later need to patch up their attributes.
This commit is contained in:
Steve Howell 2016-11-03 12:12:38 -07:00 committed by Tim Abbott
parent 15d44f8d71
commit 30e01306d9
4 changed files with 14 additions and 83 deletions

View File

@ -84,30 +84,6 @@ var _ = global._;
assert.equal(person.full_name, 'Original');
}());
(function test_reify() {
var full_person = {
email: 'foo@example.com',
full_name: 'Foo Barson'
};
// If we don't have a skeleton object, this should quietly succeed.
people.reify(full_person);
var skeleton = {
email: 'foo@example.com',
full_name: 'foo@example.com',
skeleton: true
};
people.add(skeleton);
people.reify(full_person);
var person = people.get_by_email('foo@example.com');
assert.equal(person.full_name, 'Foo Barson');
// Our follow-up reify() call should also quietly succeed.
people.reify(full_person);
}());
(function test_get_rest_of_realm() {
var myself = {
email: 'myself@example.com',

View File

@ -151,10 +151,14 @@ function insert_local_message(message_request, local_id) {
message.display_recipient = _.map(emails, function (email) {
email = email.trim();
var person = people.get_by_email(email);
if (person !== undefined) {
if (person === undefined) {
// For unknown users, we return a skeleton object.
return {email: email, full_name: email,
unknown_local_echo_user: true};
} else {
// NORMAL PATH
return person;
}
return {email: email, full_name: email, skeleton: true};
});
}
@ -232,22 +236,6 @@ exports.process_from_server = function process_from_server(messages) {
updated = true;
compose.mark_rendered_content_disparity(message.id, true);
}
// If a PM was sent to an out-of-realm address,
// we didn't have the full person object originally,
// so we might have to update the recipient bar and
// internal data structures
if (client_message.type === 'private') {
var reply_to = message_store.get_private_message_recipient(message, 'full_name', 'email');
if (client_message.display_reply_to !== reply_to) {
client_message.display_reply_to = reply_to;
_.each(message.display_recipient, function (person) {
if (people.get_by_email(person.email).full_name !== person.full_name) {
people.reify(person);
}
});
updated = true;
}
}
msgs_to_rerender.push(client_message);
locally_processed_ids.push(client_message.id);
compose.report_as_received(client_message);

View File

@ -128,20 +128,16 @@ function add_message_metadata(message) {
// Add new people involved in this message to the people list
_.each(involved_people, function (person) {
// Do the hasOwnProperty() call via the prototype to avoid problems
// with keys like "hasOwnProperty"
if (!person.unknown_local_echo_user) {
if (! people.get_by_email(person.email)) {
people.add(person);
}
if (people.get_by_email(person.email).full_name !== person.full_name) {
people.reify(person);
}
if (message.type === 'private' && message.sent_by_me) {
// Track the number of PMs we've sent to this person to improve autocomplete
people.incr_recipient_count(person.email);
}
}
});
alert_words.process_message(message);

View File

@ -129,35 +129,6 @@ exports.remove = function remove(person) {
realm_people_dict.del(person.email);
};
exports.reify = function reify(person) {
// If a locally sent message is a PM to
// an out-of-realm recipient, a people_dict
// entry is created with simply an email address
// Once we've received the full person object, replace
// it
if (! people_dict.has(person.email)) {
return;
}
var old_person = people_dict.get(person.email);
// Only overwrite skeleton objects here. If the object
// had already been reified, exit early.
if (!old_person.skeleton) {
return;
}
var new_person = _.extend({}, old_person, person);
new_person.skeleton = false;
people_dict.set(person.email, person);
people_by_name_dict.set(person.full_name, person);
if (people_by_name_dict.has(person.email)) {
people_by_name_dict.del(person.email);
}
};
exports.update = function update(person) {
if (! people_dict.has(person.email)) {
blueslip.error("Got update_person event for unexpected user",