Changeset

227:648c24de9040

mod_adhoc_cmd_admin: Add suport for showing more detail
author Florian Zeitz <florob@babelmonkeys.de>
date Fri, 30 Jul 2010 01:40:19 +0200
parents 225:95d4d53f09a1
children 229:5689ffaf97df
files mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua
diffstat 1 files changed, 20 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Thu Jul 29 14:36:41 2010 +0800
+++ b/mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua	Fri Jul 30 01:40:19 2010 +0200
@@ -108,6 +108,7 @@
 	{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
 	{ name = "max_items", type = "list-single", label = "Maximum number of users",
 		value = { "25", "50", "75", "100", "150", "200", "all" } };
+	{ name = "details", type = "boolean", label = "Show details" };
 };
 
 local get_online_users_result_layout = dataforms_new{
@@ -365,22 +366,36 @@
 			return { status = "canceled" };
 		end
 
-		local fields = add_user_layout:data(data.form);
-		
+		local fields = get_online_users_layout:data(data.form);
+
 		local max_items = nil
 		if fields.max_items ~= "all" then
 			max_items = tonumber(fields.max_items);
 		end
 		local count = 0;
-		local users = nil;
+		local users = {};
 		for username, user in pairs(hosts[data.to].sessions or {}) do
 			if (max_items ~= nil) and (count >= max_items) then
 				break;
 			end
-			users = ((users and users.."\n") or "")..(username.."@"..data.to);
+			users[#users+1] = username.."@"..data.to;
 			count = count + 1;
+			if fields.details then
+				for resource, session in pairs(user.sessions or {}) do
+					local status, priority = "unavailable", tostring(session.priority or "-");
+					if session.presence then
+						status = session.presence:child_with_name("show");
+						if status then
+							status = status:get_text() or "[invalid!]";
+						else
+							status = "available";
+						end
+					end
+					users[#users+1] = " - "..resource..": "..status.."("..priority..")";
+				end
+			end
 		end
-		return { status = "completed", result = {layout = get_online_users_result_layout, data = {onlineuserjids=users}} };
+		return { status = "completed", result = {layout = get_online_users_result_layout, data = {onlineuserjids=t_concat(users, "\n")}} };
 	else
 		return { status = "executing", form = get_online_users_layout }, "executing";
 	end