# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1582392770 -3600
# Node ID 52c6dfa04dba2d4eaa5d858c9075fb25659df2bc
# Parent  197ba9539390a78e1971a03d7b0472f87b3c982f
mod_admin_telnet: Fix host selection filter, fixes loading on components

get_hosts_with_module(a component, mod) would still filter out
components since they don't have type="component" instead of "local"

Introduced in 4d3549e64489

diff -r 197ba9539390 -r 52c6dfa04dba plugins/mod_admin_telnet.lua
--- a/plugins/mod_admin_telnet.lua	Sat Feb 22 18:23:38 2020 +0100
+++ b/plugins/mod_admin_telnet.lua	Sat Feb 22 18:32:50 2020 +0100
@@ -385,10 +385,24 @@
 local function get_hosts_with_module(hosts, module)
 	local hosts_set = get_hosts_set(hosts)
 	/ function (host)
-			if prosody.hosts[host].type == "local" or module and modulemanager.is_loaded(host, module) then
-				return host;
+			if module then
+				-- Module given, filter in hosts with this module loaded
+				if modulemanager.is_loaded(host, module) then
+					return host;
+				else
+					return nil;
+				end
+			end
+			if not hosts then
+				-- No hosts given, filter in VirtualHosts
+				if prosody.hosts[host].type == "local" then
+					return host;
+				else
+					return nil
+				end
 			end;
-			return nil;
+			-- No module given, but hosts are, don't filter at all
+			return host;
 		end;
 	if module and modulemanager.get_module("*", module) then
 		hosts_set:add("*");