From 654c9960baca8e681720fc7d833feaf98bfe9b73 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 29 Jul 2022 17:51:19 +0100 Subject: [PATCH] Properly handle networks when looking up users' online status --- core/lib/opensearch.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 86bc2be..a5f714e 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -44,27 +44,30 @@ def annotate_results(results_parsed): for net in nets: # Annotate the online attribute from Threshold - online_info = annotate_online( - net, [x["nick"] for x in results_parsed if x["src"] == "irc"] - ) + nicks = [ + x["nick"] for x in results_parsed if x["src"] == "irc" and x["net"] == net + ] + channels = [ + x["channel"] + for x in results_parsed + if x["src"] == "irc" and x["net"] == net + ] + online_info = annotate_online(net, nicks) # Annotate the number of users in the channel - num_users = annotate_num_users( - net, [x["channel"] for x in results_parsed if x["src"] == "irc"] - ) + num_users = annotate_num_users(net, channels) # Annotate the number channels the user is on - num_chans = annotate_num_chans( - net, [x["nick"] for x in results_parsed if x["src"] == "irc"] - ) + num_chans = annotate_num_chans(net, nicks) for item in results_parsed: - if "nick" in item: - if item["nick"] in online_info: - item["online"] = online_info[item["nick"]] - if "channel" in item: - if item["channel"] in num_users: - item["num_users"] = num_users[item["channel"]] - if "nick" in item: - if item["nick"] in num_chans: - item["num_chans"] = num_chans[item["nick"]] + if item["net"] == net: + if "nick" in item: + if item["nick"] in online_info: + item["online"] = online_info[item["nick"]] + if "channel" in item: + if item["channel"] in num_users: + item["num_users"] = num_users[item["channel"]] + if "nick" in item: + if item["nick"] in num_chans: + item["num_chans"] = num_chans[item["nick"]] def filter_blacklisted(user, response):