plugins/muc/muc.lib.lua
changeset 6200 57bc52f67564
parent 6199 fa858cd913b1
child 6201 b9e8f5268c97
equal deleted inserted replaced
6199:fa858cd913b1 6200:57bc52f67564
   395 		self:route_stanza(msg);
   395 		self:route_stanza(msg);
   396 	end
   396 	end
   397 end
   397 end
   398 
   398 
   399 function room_mt:get_disco_info(stanza)
   399 function room_mt:get_disco_info(stanza)
   400 	local count = 0; for _ in self:each_occupant() do count = count + 1; end
   400 	local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info");
   401 	return st.reply(stanza):query("http://jabber.org/protocol/disco#info")
   401 	local form = dataform.new {
   402 		:tag("identity", {category="conference", type="text", name=self:get_name()}):up()
   402 		{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" };
   403 		:tag("feature", {var="http://jabber.org/protocol/muc"}):up()
   403 	};
   404 		:tag("feature", {var=self:get_password() and "muc_passwordprotected" or "muc_unsecured"}):up()
   404 	module:fire_event("muc-disco#info", {room = self; reply = reply; form = form;});
   405 		:tag("feature", {var=self:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up()
   405 	reply:add_child(form:form(nil, "result"));
   406 		:tag("feature", {var=self:get_members_only() and "muc_membersonly" or "muc_open"}):up()
   406 	return reply;
   407 		:tag("feature", {var=self:get_persistent() and "muc_persistent" or "muc_temporary"}):up()
   407 end
   408 		:tag("feature", {var=self:get_hidden() and "muc_hidden" or "muc_public"}):up()
   408 module:hook("muc-disco#info", function(event)
   409 		:tag("feature", {var=self:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up()
   409 	event.reply:tag("identity", {category="conference", type="text", name=event.room:get_name()}):up();
   410 		:add_child(dataform.new({
   410 end);
   411 			{ name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" },
   411 module:hook("muc-disco#info", function(event)
   412 			{ name = "muc#roominfo_description", label = "Description", value = "" },
   412 	event.reply:tag("feature", {var = "http://jabber.org/protocol/muc"}):up();
   413 			{ name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }
   413 end);
   414 		}):form({["muc#roominfo_description"] = self:get_description()}, 'result'))
   414 module:hook("muc-disco#info", function(event)
   415 	;
   415 	event.reply:tag("feature", {var = event.room:get_password() and "muc_passwordprotected" or "muc_unsecured"}):up();
   416 end
   416 end);
       
   417 module:hook("muc-disco#info", function(event)
       
   418 	event.reply:tag("feature", {var = event.room:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up();
       
   419 end);
       
   420 module:hook("muc-disco#info", function(event)
       
   421 	event.reply:tag("feature", {var = event.room:get_members_only() and "muc_membersonly" or "muc_open"}):up();
       
   422 end);
       
   423 module:hook("muc-disco#info", function(event)
       
   424 	event.reply:tag("feature", {var = event.room:get_persistent() and "muc_persistent" or "muc_temporary"}):up();
       
   425 end);
       
   426 module:hook("muc-disco#info", function(event)
       
   427 	event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up();
       
   428 end);
       
   429 module:hook("muc-disco#info", function(event)
       
   430 	event.reply:tag("feature", {var = event.room:get_whois() ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up();
       
   431 end);
       
   432 module:hook("muc-disco#info", function(event)
       
   433 	table.insert(event.form, { name = "muc#roominfo_description", label = "Description", value = event.room:get_description() });
       
   434 end);
       
   435 module:hook("muc-disco#info", function(event)
       
   436 	local count = 0; for _ in event.room:each_occupant() do count = count + 1; end
       
   437 	table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) });
       
   438 end);
       
   439 
   417 function room_mt:get_disco_items(stanza)
   440 function room_mt:get_disco_items(stanza)
   418 	local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
   441 	local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
   419 	for room_jid in self:each_occupant() do
   442 	for room_jid in self:each_occupant() do
   420 		reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up();
   443 		reply:tag("item", {jid = room_jid, name = room_jid:match("/(.*)")}):up();
   421 	end
   444 	end