mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
refactor: Use early-return in extract_people_from_message().
This commit is contained in:
@@ -431,6 +431,12 @@ initialize();
|
||||
initialize();
|
||||
|
||||
(function test_extract_people_from_message() {
|
||||
var unknown_user = {
|
||||
email: 'unknown@example.com',
|
||||
user_id: 500,
|
||||
unknown_local_echo_user: true,
|
||||
};
|
||||
|
||||
var maria = {
|
||||
email: 'athens@example.com',
|
||||
user_id: 452,
|
||||
@@ -446,6 +452,13 @@ initialize();
|
||||
assert(!people.is_known_user_id(maria.user_id));
|
||||
people.extract_people_from_message(message);
|
||||
assert(people.is_known_user_id(maria.user_id));
|
||||
|
||||
// Get line coverage
|
||||
message = {
|
||||
type: 'private',
|
||||
display_recipient: [unknown_user],
|
||||
};
|
||||
people.extract_people_from_message(message);
|
||||
}());
|
||||
|
||||
initialize();
|
||||
|
||||
@@ -744,20 +744,23 @@ exports.extract_people_from_message = function (message) {
|
||||
|
||||
// Add new people involved in this message to the people list
|
||||
_.each(involved_people, function (person) {
|
||||
if (!person.unknown_local_echo_user) {
|
||||
|
||||
var user_id = person.user_id || person.id;
|
||||
|
||||
if (!people_by_user_id_dict.has(user_id)) {
|
||||
exports.add({
|
||||
email: person.email,
|
||||
user_id: user_id,
|
||||
full_name: person.full_name,
|
||||
is_admin: person.is_realm_admin || false,
|
||||
is_bot: person.is_bot || false,
|
||||
});
|
||||
}
|
||||
if (person.unknown_local_echo_user) {
|
||||
return;
|
||||
}
|
||||
|
||||
var user_id = person.user_id || person.id;
|
||||
|
||||
if (people_by_user_id_dict.has(user_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
exports.add({
|
||||
email: person.email,
|
||||
user_id: user_id,
|
||||
full_name: person.full_name,
|
||||
is_admin: person.is_realm_admin || false,
|
||||
is_bot: person.is_bot || false,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user