plugins/muc/muc.lib.lua

changeset 3517
530f7de1d265
parent 3516
de54a7ab7e6e
child 3540
bc139431830b
equal deleted inserted replaced
3516:de54a7ab7e6e 3517:530f7de1d265
9 local select = select; 9 local select = select;
10 local pairs, ipairs = pairs, ipairs; 10 local pairs, ipairs = pairs, ipairs;
11 11
12 local datamanager = require "util.datamanager"; 12 local datamanager = require "util.datamanager";
13 local datetime = require "util.datetime"; 13 local datetime = require "util.datetime";
14
15 local dataform = require "util.dataforms";
14 16
15 local jid_split = require "util.jid".split; 17 local jid_split = require "util.jid".split;
16 local jid_bare = require "util.jid".bare; 18 local jid_bare = require "util.jid".bare;
17 local jid_prep = require "util.jid".prep; 19 local jid_prep = require "util.jid".prep;
18 local st = require "util.stanza"; 20 local st = require "util.stanza";
218 :tag("feature", {var=self:is_moderated() and "muc_moderated" or "muc_unmoderated"}):up() 220 :tag("feature", {var=self:is_moderated() and "muc_moderated" or "muc_unmoderated"}):up()
219 :tag("feature", {var=self:is_members_only() and "muc_membersonly" or "muc_open"}):up() 221 :tag("feature", {var=self:is_members_only() and "muc_membersonly" or "muc_open"}):up()
220 :tag("feature", {var=self:is_persistent() and "muc_persistent" or "muc_temporary"}):up() 222 :tag("feature", {var=self:is_persistent() and "muc_persistent" or "muc_temporary"}):up()
221 :tag("feature", {var=self:is_hidden() and "muc_hidden" or "muc_public"}):up() 223 :tag("feature", {var=self:is_hidden() and "muc_hidden" or "muc_public"}):up()
222 :tag("feature", {var=self._data.whois ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up() 224 :tag("feature", {var=self._data.whois ~= "anyone" and "muc_semianonymous" or "muc_nonanonymous"}):up()
223 :tag("x", {xmlns="jabber:x:data", type="result"}) 225 :add_child(dataform.new({
224 :tag("field", {var="FORM_TYPE", type="hidden"}) 226 { name = "FORM_TYPE", type = "hidden", value = "http://jabber.org/protocol/muc#roominfo" },
225 :tag("value"):text("http://jabber.org/protocol/muc#roominfo"):up() 227 { name = "muc#roominfo_description", label = "Description"}
226 :up() 228 }):form({["muc#roominfo_description"] = self:get_description()}, 'result'))
227 :tag("field", {var="muc#roominfo_description", label="Description"})
228 :tag("value"):text(self:get_description()):up()
229 :up()
230 :up()
231 ; 229 ;
232 end 230 end
233 function room_mt:get_disco_items(stanza) 231 function room_mt:get_disco_items(stanza)
234 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); 232 local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items");
235 for room_jid in pairs(self._occupants) do 233 for room_jid in pairs(self._occupants) do
524 end 522 end
525 523
526 function room_mt:send_form(origin, stanza) 524 function room_mt:send_form(origin, stanza)
527 local title = "Configuration for "..self.jid; 525 local title = "Configuration for "..self.jid;
528 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner") 526 origin.send(st.reply(stanza):query("http://jabber.org/protocol/muc#owner")
529 :tag("x", {xmlns='jabber:x:data', type='form'}) 527 :add_child(dataform.new({
530 :tag("title"):text(title):up() 528 title = title,
531 :tag("instructions"):text(title):up() 529 instructions = title,
532 :tag("field", {type='hidden', var='FORM_TYPE'}):tag("value"):text("http://jabber.org/protocol/muc#roomconfig"):up():up() 530 {
533 :tag("field", {type='text-single', label='Name', var='muc#roomconfig_roomname'}) 531 name = 'FORM_TYPE',
534 :tag("value"):text(self:get_name() or ""):up() 532 type = 'hidden',
535 :up() 533 value = 'http://jabber.org/protocol/muc#roomconfig'
536 :tag("field", {type='text-single', label='Description', var='muc#roomconfig_roomdesc'}) 534 },
537 :tag("value"):text(self:get_description() or ""):up() 535 {
538 :up() 536 name = 'muc#roomconfig_roomname',
539 :tag("field", {type='boolean', label='Make Room Persistent?', var='muc#roomconfig_persistentroom'}) 537 type = 'text-single',
540 :tag("value"):text(self:is_persistent() and "1" or "0"):up() 538 label = 'Name',
541 :up() 539 value = self:get_name() or "",
542 :tag("field", {type='boolean', label='Make Room Publicly Searchable?', var='muc#roomconfig_publicroom'}) 540 },
543 :tag("value"):text(self:is_hidden() and "0" or "1"):up() 541 {
544 :up() 542 name = 'muc#roomconfig_roomdesc',
545 :tag("field", {type='list-single', label='Who May Discover Real JIDs?', var='muc#roomconfig_whois'}) 543 type = 'text-single',
546 :tag("value"):text(self._data.whois or 'moderators'):up() 544 label = 'Description',
547 :tag("option", {label = 'Moderators Only'}) 545 value = self:get_description() or "",
548 :tag("value"):text('moderators'):up() 546 },
549 :up() 547 {
550 :tag("option", {label = 'Anyone'}) 548 name = 'muc#roomconfig_persistentroom',
551 :tag("value"):text('anyone'):up() 549 type = 'boolean',
552 :up() 550 label = 'Make Room Persistent?',
553 :up() 551 value = self:is_persistent()
554 :tag("field", {type='text-private', label='Password', var='muc#roomconfig_roomsecret'}) 552 },
555 :tag("value"):text(self:get_password() or ""):up() 553 {
556 :up() 554 name = 'muc#roomconfig_publicroom',
557 :tag("field", {type='boolean', label='Make Room Moderated?', var='muc#roomconfig_moderatedroom'}) 555 type = 'boolean',
558 :tag("value"):text(self:is_moderated() and "1" or "0"):up() 556 label = 'Make Room Publicly Searchable?',
559 :up() 557 value = not self:is_hidden()
560 :tag("field", {type='boolean', label='Make Room Members-Only?', var='muc#roomconfig_membersonly'}) 558 },
561 :tag("value"):text(self:is_members_only() and "1" or "0"):up() 559 {
562 :up() 560 name = 'muc#roomconfig_whois',
561 type = 'list-single',
562 label = 'Who May Discover Real JIDs?',
563 value = {
564 { value = 'moderators', label = 'Moderators Only', default = self._data.whois == 'moderators' },
565 { value = 'anyone', label = 'Anyone', default = self._data.whois == 'anyone' }
566 }
567 },
568 {
569 name = 'muc#roomconfig_roomsecret',
570 type = 'text-private',
571 label = 'Password',
572 value = self:get_password() or "",
573 },
574 {
575 name = 'muc#roomconfig_moderatedroom',
576 type = 'boolean',
577 label = 'Make Room Moderated?',
578 value = self:is_moderated()
579 },
580 {
581 name = 'muc#roomconfig_membersonly',
582 type = 'boolean',
583 label = 'Make Room Members-Only?',
584 value = self:is_members_only()
585 }
586 }):form())
563 ); 587 );
564 end 588 end
565 589
566 local valid_whois = { 590 local valid_whois = {
567 moderators = true, 591 moderators = true,

mercurial