From aa47ca0ac075fd9f726702c8ab72f8ffe78ef685 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Bodas Date: Fri, 23 Apr 2021 20:25:26 +0530 Subject: [PATCH] buddy_data: Move all user_id filtering code to `filter_user_ids`. This makes the naming more intuitive and gives us a single place to add more conditions on filtering user_ids, with the current motivation being filtering muted users, the logic for which will be added in further commits. --- static/js/buddy_data.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js index 1d95c15ef8..75a5ba1796 100644 --- a/static/js/buddy_data.js +++ b/static/js/buddy_data.js @@ -309,10 +309,25 @@ function maybe_shrink_list(user_ids, user_filter_text) { } function filter_user_ids(user_filter_text, user_ids) { + // This first filter is for whether the user is eligible to be + // displayed in the right sidebar at all. + user_ids = user_ids.filter((user_id) => { + const person = people.get_by_user_id(user_id); + + if (!person) { + blueslip.warn("Got user_id in presence but not people: " + user_id); + return false; + } + + // if the user is bot, do not show in presence data. + return !person.is_bot; + }); + if (!user_filter_text) { return user_ids; } + // If a query is present in "Filter users", we return matches. user_ids = user_ids.filter((user_id) => !people.is_my_user_id(user_id)); let search_terms = user_filter_text.toLowerCase().split(/[,|]+/); @@ -321,6 +336,7 @@ function filter_user_ids(user_filter_text, user_ids) { const persons = user_ids.map((user_id) => people.get_by_user_id(user_id)); const user_id_dict = people.filter_people_by_search_terms(persons, search_terms); + return Array.from(user_id_dict.keys()); } @@ -338,19 +354,7 @@ function get_user_id_list(user_filter_text) { base_user_id_list = presence.get_user_ids(); } - let user_ids = filter_user_ids(user_filter_text, base_user_id_list); - - user_ids = user_ids.filter((user_id) => { - const person = people.get_by_user_id(user_id); - - if (!person) { - blueslip.warn("Got user_id in presence but not people: " + user_id); - return false; - } - - // if the user is bot, do not show in presence data. - return !person.is_bot; - }); + const user_ids = filter_user_ids(user_filter_text, base_user_id_list); return user_ids; }