mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
refactor: Extract people.maybe_incr_recipient_count().
This logic used to be in extract_people_from_message(), but we are deprecating extract_people_from_message(), whereas the maybe_incr_recipient_count() function has logic that we want to keep.
This commit is contained in:
@@ -443,15 +443,58 @@ initialize();
|
|||||||
sender_id: maria.user_id,
|
sender_id: maria.user_id,
|
||||||
sender_email: maria.email,
|
sender_email: maria.email,
|
||||||
};
|
};
|
||||||
|
assert(!people.is_known_user_id(maria.user_id));
|
||||||
people.extract_people_from_message(message);
|
people.extract_people_from_message(message);
|
||||||
assert(people.is_known_user_id(maria.user_id));
|
assert(people.is_known_user_id(maria.user_id));
|
||||||
|
}());
|
||||||
|
|
||||||
message = {
|
initialize();
|
||||||
|
|
||||||
|
(function test_maybe_incr_recipient_count() {
|
||||||
|
var maria = {
|
||||||
|
email: 'athens@example.com',
|
||||||
|
user_id: 452,
|
||||||
|
full_name: 'Maria Athens',
|
||||||
|
};
|
||||||
|
people.add_in_realm(maria);
|
||||||
|
|
||||||
|
var unknown_user = {
|
||||||
|
email: 'unknown@example.com',
|
||||||
|
user_id: 500,
|
||||||
|
unknown_local_echo_user: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
var message = {
|
||||||
type: 'private',
|
type: 'private',
|
||||||
display_recipient: [maria],
|
display_recipient: [maria],
|
||||||
sent_by_me: true,
|
sent_by_me: true,
|
||||||
};
|
};
|
||||||
people.extract_people_from_message(message);
|
assert.equal(people.get_recipient_count(maria), 0);
|
||||||
|
people.maybe_incr_recipient_count(message);
|
||||||
|
assert.equal(people.get_recipient_count(maria), 1);
|
||||||
|
|
||||||
|
// Test all the no-op conditions to get test
|
||||||
|
// coverage.
|
||||||
|
message = {
|
||||||
|
type: 'private',
|
||||||
|
sent_by_me: false,
|
||||||
|
display_recipient: [maria],
|
||||||
|
};
|
||||||
|
people.maybe_incr_recipient_count(message);
|
||||||
|
assert.equal(people.get_recipient_count(maria), 1);
|
||||||
|
|
||||||
|
message = {
|
||||||
|
type: 'private',
|
||||||
|
sent_by_me: true,
|
||||||
|
display_recipient: [unknown_user],
|
||||||
|
};
|
||||||
|
people.maybe_incr_recipient_count(message);
|
||||||
|
assert.equal(people.get_recipient_count(maria), 1);
|
||||||
|
|
||||||
|
message = {
|
||||||
|
type: 'stream',
|
||||||
|
};
|
||||||
|
people.maybe_incr_recipient_count(message);
|
||||||
assert.equal(people.get_recipient_count(maria), 1);
|
assert.equal(people.get_recipient_count(maria), 1);
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ exports.add_message_metadata = function (message) {
|
|||||||
exports.set_message_booleans(message, message.flags);
|
exports.set_message_booleans(message, message.flags);
|
||||||
|
|
||||||
people.extract_people_from_message(message);
|
people.extract_people_from_message(message);
|
||||||
|
people.maybe_incr_recipient_count(message);
|
||||||
|
|
||||||
var sender = people.get_person_from_user_id(message.sender_id);
|
var sender = people.get_person_from_user_id(message.sender_id);
|
||||||
if (sender) {
|
if (sender) {
|
||||||
|
|||||||
@@ -757,12 +757,28 @@ exports.extract_people_from_message = function (message) {
|
|||||||
is_bot: person.is_bot || false,
|
is_bot: person.is_bot || false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.maybe_incr_recipient_count = function (message) {
|
||||||
|
if (message.type !== 'private') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!message.sent_by_me) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.type === 'private' && message.sent_by_me) {
|
|
||||||
// Track the number of PMs we've sent to this person to improve autocomplete
|
// Track the number of PMs we've sent to this person to improve autocomplete
|
||||||
|
_.each(message.display_recipient, function (person) {
|
||||||
|
|
||||||
|
if (person.unknown_local_echo_user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var user_id = person.user_id || person.id;
|
||||||
exports.incr_recipient_count(user_id);
|
exports.incr_recipient_count(user_id);
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user