mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
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:
@@ -84,30 +84,6 @@ var _ = global._;
|
|||||||
assert.equal(person.full_name, 'Original');
|
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() {
|
(function test_get_rest_of_realm() {
|
||||||
var myself = {
|
var myself = {
|
||||||
email: 'myself@example.com',
|
email: 'myself@example.com',
|
||||||
|
|||||||
@@ -151,10 +151,14 @@ function insert_local_message(message_request, local_id) {
|
|||||||
message.display_recipient = _.map(emails, function (email) {
|
message.display_recipient = _.map(emails, function (email) {
|
||||||
email = email.trim();
|
email = email.trim();
|
||||||
var person = people.get_by_email(email);
|
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 person;
|
||||||
}
|
}
|
||||||
return {email: email, full_name: email, skeleton: true};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,22 +236,6 @@ exports.process_from_server = function process_from_server(messages) {
|
|||||||
updated = true;
|
updated = true;
|
||||||
compose.mark_rendered_content_disparity(message.id, 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);
|
msgs_to_rerender.push(client_message);
|
||||||
locally_processed_ids.push(client_message.id);
|
locally_processed_ids.push(client_message.id);
|
||||||
compose.report_as_received(client_message);
|
compose.report_as_received(client_message);
|
||||||
|
|||||||
@@ -128,19 +128,15 @@ function add_message_metadata(message) {
|
|||||||
|
|
||||||
// Add new people involved in this message to the people list
|
// Add new people involved in this message to the people list
|
||||||
_.each(involved_people, function (person) {
|
_.each(involved_people, function (person) {
|
||||||
// Do the hasOwnProperty() call via the prototype to avoid problems
|
if (!person.unknown_local_echo_user) {
|
||||||
// with keys like "hasOwnProperty"
|
if (! people.get_by_email(person.email)) {
|
||||||
if (! people.get_by_email(person.email)) {
|
people.add(person);
|
||||||
people.add(person);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (people.get_by_email(person.email).full_name !== person.full_name) {
|
if (message.type === 'private' && message.sent_by_me) {
|
||||||
people.reify(person);
|
// Track the number of PMs we've sent to this person to improve autocomplete
|
||||||
}
|
people.incr_recipient_count(person.email);
|
||||||
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -129,35 +129,6 @@ exports.remove = function remove(person) {
|
|||||||
realm_people_dict.del(person.email);
|
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) {
|
exports.update = function update(person) {
|
||||||
if (! people_dict.has(person.email)) {
|
if (! people_dict.has(person.email)) {
|
||||||
blueslip.error("Got update_person event for unexpected user",
|
blueslip.error("Got update_person event for unexpected user",
|
||||||
|
|||||||
Reference in New Issue
Block a user