plugins/mod_admin_shell.lua
changeset 11890 b0b258e092da
parent 11889 197642f9972f
child 11891 b043e1bb8e8e
--- a/plugins/mod_admin_shell.lua	Wed Nov 10 17:59:35 2021 +0100
+++ b/plugins/mod_admin_shell.lua	Wed Nov 10 15:54:27 2021 +0100
@@ -833,9 +833,24 @@
 		return (not match_jid) or jid:match(match_jid)
 	end
 
-	print(row());
+	local group_by_host = true;
+	for _, col in ipairs(columns) do
+		if col.key == "full_jid" or col.key == "host" then
+			group_by_host = false;
+			break
+		end
+	end
+
+	if not group_by_host then print(row()); end
+	local currenthost = nil;
 
 	for _, session in ipairs(get_c2s():filter(match):sort(_sort_by_jid)) do
+		if group_by_host and session.host ~= currenthost then
+			currenthost = session.host;
+			print("#",prosody.hosts[currenthost] or "Unknown host");
+			print(row());
+		end
+
 		print(row(session));
 	end
 	return true;
@@ -894,11 +909,26 @@
 		return not match_jid or (host or ""):match(match_jid) or (remote or ""):match(match_jid);
 	end
 
+	local group_by_host = true;
+	local currenthost = nil;
+	for _, col in ipairs(columns) do
+		if col.key == "host" then
+			group_by_host = false;
+			break
+		end
+	end
+
+	if not group_by_host then print(row()); end
+
 	local s2s_sessions = array(iterators.values(module:shared"/*/s2s/sessions")):filter(match):sort(_sort_s2s);
 
-	print(row());
+	for _, session in ipairs(s2s_sessions) do
+		if group_by_host and currenthost ~= get_s2s_hosts(session) then
+			currenthost = get_s2s_hosts(session);
+			print("#",prosody.hosts[currenthost] or "Unknown host");
+			print(row());
+		end
 
-	for _, session in ipairs(s2s_sessions) do
 		print(row(session));
 	end
 	return true; -- TODO counts