mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
refactor: Use user_id as key for pm_recipient_count.
We now key people.pm_recipient_count by user_id, which makes one less dictionary that we'll need to update when we support email updates.
This commit is contained in:
@@ -60,8 +60,21 @@ global.people.add({
|
||||
assert_typeahead_equals("test no@o", false);
|
||||
assert_typeahead_equals("test :-P", false);
|
||||
|
||||
var all_items = [{ special_item_text: 'all (Notify everyone)', email: 'all', pm_recipient_count: Infinity, full_name: 'all' },
|
||||
{ special_item_text: 'everyone (Notify everyone)', email: 'everyone', full_name: 'everyone' }];
|
||||
var all_items = [
|
||||
{
|
||||
special_item_text: 'all (Notify everyone)',
|
||||
email: 'all',
|
||||
pm_recipient_count: Infinity,
|
||||
full_name: 'all',
|
||||
},
|
||||
{
|
||||
special_item_text: 'everyone (Notify everyone)',
|
||||
email: 'everyone',
|
||||
pm_recipient_count: Infinity,
|
||||
full_name: 'everyone',
|
||||
},
|
||||
];
|
||||
|
||||
var people_with_all = global.people.get_realm_persons().concat(all_items);
|
||||
|
||||
assert_typeahead_equals("test @o", people_with_all);
|
||||
|
||||
@@ -135,11 +135,11 @@ initialize();
|
||||
initialize();
|
||||
|
||||
(function test_recipient_counts() {
|
||||
var email = 'anybody@example.com';
|
||||
assert.equal(people.get_recipient_count({email: email}), 0);
|
||||
people.incr_recipient_count(email);
|
||||
people.incr_recipient_count(email);
|
||||
assert.equal(people.get_recipient_count({email: email}), 2);
|
||||
var user_id = 99;
|
||||
assert.equal(people.get_recipient_count({id: user_id}), 0);
|
||||
people.incr_recipient_count(user_id);
|
||||
people.incr_recipient_count(user_id);
|
||||
assert.equal(people.get_recipient_count({user_id: user_id}), 2);
|
||||
|
||||
assert.equal(people.get_recipient_count({pm_recipient_count: 5}), 5);
|
||||
}());
|
||||
|
||||
@@ -286,6 +286,7 @@ exports.compose_content_begins_typeahead = function (query) {
|
||||
var everyone_item = {
|
||||
special_item_text: "everyone (Notify everyone)",
|
||||
email: "everyone",
|
||||
pm_recipient_count: Infinity,
|
||||
full_name: "everyone",
|
||||
};
|
||||
var persons = people.get_realm_persons();
|
||||
|
||||
@@ -21,7 +21,7 @@ exports.init = function () {
|
||||
// People in this realm
|
||||
realm_people_dict = new Dict({fold_case: true});
|
||||
cross_realm_dict = new Dict({fold_case: true});
|
||||
pm_recipient_count_dict = new Dict({fold_case: true});
|
||||
pm_recipient_count_dict = new Dict();
|
||||
};
|
||||
|
||||
// WE INITIALIZE DATA STRUCTURES HERE!
|
||||
@@ -249,14 +249,15 @@ exports.get_recipient_count = function (person) {
|
||||
return person.pm_recipient_count;
|
||||
}
|
||||
|
||||
var count = pm_recipient_count_dict.get(person.email);
|
||||
var user_id = person.user_id || person.id;
|
||||
var count = pm_recipient_count_dict.get(user_id);
|
||||
|
||||
return count || 0;
|
||||
};
|
||||
|
||||
exports.incr_recipient_count = function (email) {
|
||||
var old_count = pm_recipient_count_dict.get(email) || 0;
|
||||
pm_recipient_count_dict.set(email, old_count + 1);
|
||||
exports.incr_recipient_count = function (user_id) {
|
||||
var old_count = pm_recipient_count_dict.get(user_id) || 0;
|
||||
pm_recipient_count_dict.set(user_id, old_count + 1);
|
||||
};
|
||||
|
||||
exports.filter_people_by_search_terms = function (users, search_terms) {
|
||||
@@ -386,10 +387,13 @@ 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 (! exports.get_by_email(person.email)) {
|
||||
exports.add({
|
||||
email: person.email,
|
||||
user_id: person.user_id || person.id,
|
||||
user_id: user_id,
|
||||
full_name: person.full_name,
|
||||
is_admin: person.is_realm_admin || false,
|
||||
is_bot: person.is_bot || false,
|
||||
@@ -398,7 +402,7 @@ exports.extract_people_from_message = function (message) {
|
||||
|
||||
if (message.type === 'private' && message.sent_by_me) {
|
||||
// Track the number of PMs we've sent to this person to improve autocomplete
|
||||
exports.incr_recipient_count(person.email);
|
||||
exports.incr_recipient_count(user_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user