Mercurial > prosody-hg
comparison plugins/muc/muc.lib.lua @ 6225:12537f1c1fec
plugins/muc: Move 'hidden' ('public') code to own file
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Wed, 16 Apr 2014 14:16:14 -0400 |
| parents | 2a9aff163545 |
| children | 7582deb85812 |
comparison
equal
deleted
inserted
replaced
| 6224:2a9aff163545 | 6225:12537f1c1fec |
|---|---|
| 279 end); | 279 end); |
| 280 module:hook("muc-disco#info", function(event) | 280 module:hook("muc-disco#info", function(event) |
| 281 event.reply:tag("feature", {var = event.room:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up(); | 281 event.reply:tag("feature", {var = event.room:get_moderated() and "muc_moderated" or "muc_unmoderated"}):up(); |
| 282 end); | 282 end); |
| 283 module:hook("muc-disco#info", function(event) | 283 module:hook("muc-disco#info", function(event) |
| 284 event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up(); | |
| 285 end); | |
| 286 module:hook("muc-disco#info", function(event) | |
| 287 local count = iterators.count(event.room:each_occupant()); | 284 local count = iterators.count(event.room:each_occupant()); |
| 288 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); | 285 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); |
| 289 end); | 286 end); |
| 290 | 287 |
| 291 function room_mt:get_disco_items(stanza) | 288 function room_mt:get_disco_items(stanza) |
| 321 if self.save then self:save(true); end | 318 if self.save then self:save(true); end |
| 322 end | 319 end |
| 323 end | 320 end |
| 324 function room_mt:get_moderated() | 321 function room_mt:get_moderated() |
| 325 return self._data.moderated; | 322 return self._data.moderated; |
| 326 end | |
| 327 function room_mt:set_hidden(hidden) | |
| 328 hidden = hidden and true or nil; | |
| 329 if self._data.hidden ~= hidden then | |
| 330 self._data.hidden = hidden; | |
| 331 if self.save then self:save(true); end | |
| 332 end | |
| 333 end | |
| 334 function room_mt:get_hidden() | |
| 335 return self._data.hidden; | |
| 336 end | |
| 337 function room_mt:get_public() | |
| 338 return not self:get_hidden(); | |
| 339 end | |
| 340 function room_mt:set_public(public) | |
| 341 return self:set_hidden(not public); | |
| 342 end | 323 end |
| 343 | 324 |
| 344 -- Give the room creator owner affiliation | 325 -- Give the room creator owner affiliation |
| 345 module:hook("muc-room-pre-create", function(event) | 326 module:hook("muc-room-pre-create", function(event) |
| 346 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); | 327 event.room:set_affiliation(true, jid_bare(event.stanza.attr.from), "owner"); |
| 621 }); | 602 }); |
| 622 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 603 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
| 623 end | 604 end |
| 624 module:hook("muc-config-form", function(event) | 605 module:hook("muc-config-form", function(event) |
| 625 table.insert(event.form, { | 606 table.insert(event.form, { |
| 626 name = 'muc#roomconfig_publicroom', | |
| 627 type = 'boolean', | |
| 628 label = 'Make Room Publicly Searchable?', | |
| 629 value = not event.room:get_hidden() | |
| 630 }); | |
| 631 end); | |
| 632 module:hook("muc-config-form", function(event) | |
| 633 table.insert(event.form, { | |
| 634 name = 'muc#roomconfig_moderatedroom', | 607 name = 'muc#roomconfig_moderatedroom', |
| 635 type = 'boolean', | 608 type = 'boolean', |
| 636 label = 'Make Room Moderated?', | 609 label = 'Make Room Moderated?', |
| 637 value = event.room:get_moderated() | 610 value = event.room:get_moderated() |
| 638 }); | 611 }); |
| 678 end | 651 end |
| 679 return true; | 652 return true; |
| 680 end | 653 end |
| 681 module:hook("muc-config-submitted", function(event) | 654 module:hook("muc-config-submitted", function(event) |
| 682 event.update_option("moderated", "muc#roomconfig_moderatedroom"); | 655 event.update_option("moderated", "muc#roomconfig_moderatedroom"); |
| 683 end); | |
| 684 module:hook("muc-config-submitted", function(event) | |
| 685 event.update_option("public", "muc#roomconfig_publicroom"); | |
| 686 end); | 656 end); |
| 687 | 657 |
| 688 -- Removes everyone from the room | 658 -- Removes everyone from the room |
| 689 function room_mt:clear(x) | 659 function room_mt:clear(x) |
| 690 x = x or st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); | 660 x = x or st.stanza("x", {xmlns='http://jabber.org/protocol/muc#user'}); |
| 1125 | 1095 |
| 1126 local description = module:require "muc/description"; | 1096 local description = module:require "muc/description"; |
| 1127 room_mt.get_description = description.get; | 1097 room_mt.get_description = description.get; |
| 1128 room_mt.set_description = description.set; | 1098 room_mt.set_description = description.set; |
| 1129 | 1099 |
| 1100 local hidden = module:require "muc/hidden"; | |
| 1101 room_mt.get_hidden = hidden.get; | |
| 1102 room_mt.set_hidden = hidden.set; | |
| 1103 function room_mt:get_public() | |
| 1104 return not self:get_hidden(); | |
| 1105 end | |
| 1106 function room_mt:set_public(public) | |
| 1107 return self:set_hidden(not public); | |
| 1108 end | |
| 1109 | |
| 1130 local password = module:require "muc/password"; | 1110 local password = module:require "muc/password"; |
| 1131 room_mt.get_password = password.get; | 1111 room_mt.get_password = password.get; |
| 1132 room_mt.set_password = password.set; | 1112 room_mt.set_password = password.set; |
| 1133 | 1113 |
| 1134 local whois = module:require "muc/whois"; | 1114 local whois = module:require "muc/whois"; |
