mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
presence: Add warning for missing user_id.
This is defensive code for the scenario that we have a user_id in presence but not people. This is unlikely to occur by the time that we actually render the buddy list, which is the context for this code. We have previously been reporting an error here via the people code, but we add an additional warning. Also, we filter the user_id from the result.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const _page_params = {};
|
||||
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
set_global('page_params', _page_params);
|
||||
set_global('i18n', global.stub_i18n);
|
||||
set_global('$', global.make_zjquery());
|
||||
@@ -281,3 +283,12 @@ run_test('user_last_seen_time_status', () => {
|
||||
'May 12');
|
||||
|
||||
});
|
||||
|
||||
run_test('error handling', () => {
|
||||
presence.get_user_ids = () => [42];
|
||||
blueslip.set_test_data('error', 'Unknown user_id in get_person_from_user_id: 42');
|
||||
blueslip.set_test_data('warn', 'Got user_id in presence but not people: 42');
|
||||
buddy_data.get_filtered_and_sorted_user_ids();
|
||||
assert.equal(blueslip.get_test_logs('error').length, 1);
|
||||
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
||||
});
|
||||
|
||||
@@ -314,13 +314,13 @@ exports.get_filtered_and_sorted_user_ids = function (filter_text) {
|
||||
user_ids = _.filter(user_ids, function (user_id) {
|
||||
const person = people.get_person_from_user_id(user_id);
|
||||
|
||||
if (person) {
|
||||
// if the user is bot, do not show in presence data.
|
||||
if (person.is_bot) {
|
||||
return false;
|
||||
}
|
||||
if (!person) {
|
||||
blueslip.warn('Got user_id in presence but not people: ' + user_id);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
// if the user is bot, do not show in presence data.
|
||||
return !person.is_bot;
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user