comparison mod_adhoc_cmd_admin/mod_adhoc_cmd_admin.lua @ 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 d15c7d86db11
children 161067865850
comparison
equal deleted inserted replaced
225:95d4d53f09a1 227:648c24de9040
106 instructions = "How many users should be returned at most?"; 106 instructions = "How many users should be returned at most?";
107 107
108 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; 108 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
109 { name = "max_items", type = "list-single", label = "Maximum number of users", 109 { name = "max_items", type = "list-single", label = "Maximum number of users",
110 value = { "25", "50", "75", "100", "150", "200", "all" } }; 110 value = { "25", "50", "75", "100", "150", "200", "all" } };
111 { name = "details", type = "boolean", label = "Show details" };
111 }; 112 };
112 113
113 local get_online_users_result_layout = dataforms_new{ 114 local get_online_users_result_layout = dataforms_new{
114 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" }; 115 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/admin" };
115 { name = "onlineuserjids", type = "text-multi", label = "The list of all online users" }; 116 { name = "onlineuserjids", type = "text-multi", label = "The list of all online users" };
363 if state then 364 if state then
364 if data.action == "cancel" then 365 if data.action == "cancel" then
365 return { status = "canceled" }; 366 return { status = "canceled" };
366 end 367 end
367 368
368 local fields = add_user_layout:data(data.form); 369 local fields = get_online_users_layout:data(data.form);
369 370
370 local max_items = nil 371 local max_items = nil
371 if fields.max_items ~= "all" then 372 if fields.max_items ~= "all" then
372 max_items = tonumber(fields.max_items); 373 max_items = tonumber(fields.max_items);
373 end 374 end
374 local count = 0; 375 local count = 0;
375 local users = nil; 376 local users = {};
376 for username, user in pairs(hosts[data.to].sessions or {}) do 377 for username, user in pairs(hosts[data.to].sessions or {}) do
377 if (max_items ~= nil) and (count >= max_items) then 378 if (max_items ~= nil) and (count >= max_items) then
378 break; 379 break;
379 end 380 end
380 users = ((users and users.."\n") or "")..(username.."@"..data.to); 381 users[#users+1] = username.."@"..data.to;
381 count = count + 1; 382 count = count + 1;
382 end 383 if fields.details then
383 return { status = "completed", result = {layout = get_online_users_result_layout, data = {onlineuserjids=users}} }; 384 for resource, session in pairs(user.sessions or {}) do
385 local status, priority = "unavailable", tostring(session.priority or "-");
386 if session.presence then
387 status = session.presence:child_with_name("show");
388 if status then
389 status = status:get_text() or "[invalid!]";
390 else
391 status = "available";
392 end
393 end
394 users[#users+1] = " - "..resource..": "..status.."("..priority..")";
395 end
396 end
397 end
398 return { status = "completed", result = {layout = get_online_users_result_layout, data = {onlineuserjids=t_concat(users, "\n")}} };
384 else 399 else
385 return { status = "executing", form = get_online_users_layout }, "executing"; 400 return { status = "executing", form = get_online_users_layout }, "executing";
386 end 401 end
387 end 402 end
388 403