Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6222:355b29881117
plugins/muc: Move persistent room configuration to own module
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 15 Apr 2014 17:06:04 -0400 |
parent | 6221:f321536afeec |
child | 6223:2a7ce69844ca |
comparison
equal
deleted
inserted
replaced
6221:f321536afeec | 6222:355b29881117 |
---|---|
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_persistent() and "muc_persistent" or "muc_temporary"}):up(); | |
285 end); | |
286 module:hook("muc-disco#info", function(event) | |
287 event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up(); | 284 event.reply:tag("feature", {var = event.room:get_hidden() and "muc_hidden" or "muc_public"}):up(); |
288 end); | 285 end); |
289 module:hook("muc-disco#info", function(event) | 286 module:hook("muc-disco#info", function(event) |
290 local count = iterators.count(event.room:each_occupant()); | 287 local count = iterators.count(event.room:each_occupant()); |
291 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); | 288 table.insert(event.form, { name = "muc#roominfo_occupants", label = "Number of occupants", value = tostring(count) }); |
346 if self.save then self:save(true); end | 343 if self.save then self:save(true); end |
347 end | 344 end |
348 end | 345 end |
349 function room_mt:get_moderated() | 346 function room_mt:get_moderated() |
350 return self._data.moderated; | 347 return self._data.moderated; |
351 end | |
352 function room_mt:set_persistent(persistent) | |
353 persistent = persistent and true or nil; | |
354 if self._data.persistent ~= persistent then | |
355 self._data.persistent = persistent; | |
356 if self.save then self:save(true); end | |
357 end | |
358 end | |
359 function room_mt:get_persistent() | |
360 return self._data.persistent; | |
361 end | 348 end |
362 function room_mt:set_hidden(hidden) | 349 function room_mt:set_hidden(hidden) |
363 hidden = hidden and true or nil; | 350 hidden = hidden and true or nil; |
364 if self._data.hidden ~= hidden then | 351 if self._data.hidden ~= hidden then |
365 self._data.hidden = hidden; | 352 self._data.hidden = hidden; |
671 }); | 658 }); |
672 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; | 659 return module:fire_event("muc-config-form", { room = self, actor = actor, form = form }) or form; |
673 end | 660 end |
674 module:hook("muc-config-form", function(event) | 661 module:hook("muc-config-form", function(event) |
675 table.insert(event.form, { | 662 table.insert(event.form, { |
676 name = 'muc#roomconfig_persistentroom', | |
677 type = 'boolean', | |
678 label = 'Make Room Persistent?', | |
679 value = event.room:get_persistent() | |
680 }); | |
681 end); | |
682 module:hook("muc-config-form", function(event) | |
683 table.insert(event.form, { | |
684 name = 'muc#roomconfig_publicroom', | 663 name = 'muc#roomconfig_publicroom', |
685 type = 'boolean', | 664 type = 'boolean', |
686 label = 'Make Room Publicly Searchable?', | 665 label = 'Make Room Publicly Searchable?', |
687 value = not event.room:get_hidden() | 666 value = not event.room:get_hidden() |
688 }); | 667 }); |
743 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); | 722 origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); |
744 end | 723 end |
745 return true; | 724 return true; |
746 end | 725 end |
747 module:hook("muc-config-submitted", function(event) | 726 module:hook("muc-config-submitted", function(event) |
748 event.update_option("persistent", "muc#roomconfig_persistentroom"); | |
749 end); | |
750 module:hook("muc-config-submitted", function(event) | |
751 event.update_option("moderated", "muc#roomconfig_moderatedroom"); | 727 event.update_option("moderated", "muc#roomconfig_moderatedroom"); |
752 end); | 728 end); |
753 module:hook("muc-config-submitted", function(event) | 729 module:hook("muc-config-submitted", function(event) |
754 event.update_option("public", "muc#roomconfig_publicroom"); | 730 event.update_option("public", "muc#roomconfig_publicroom"); |
755 end); | 731 end); |
778 :tag("destroy", {jid=newjid}); | 754 :tag("destroy", {jid=newjid}); |
779 if reason then x:tag("reason"):text(reason):up(); end | 755 if reason then x:tag("reason"):text(reason):up(); end |
780 if password then x:tag("password"):text(password):up(); end | 756 if password then x:tag("password"):text(password):up(); end |
781 x:up(); | 757 x:up(); |
782 self:clear(x); | 758 self:clear(x); |
783 self:set_persistent(false); | |
784 module:fire_event("muc-room-destroyed", { room = self }); | 759 module:fire_event("muc-room-destroyed", { room = self }); |
785 end | 760 end |
786 | 761 |
787 function room_mt:handle_disco_info_get_query(origin, stanza) | 762 function room_mt:handle_disco_info_get_query(origin, stanza) |
788 origin.send(self:get_disco_info(stanza)); | 763 origin.send(self:get_disco_info(stanza)); |
1218 | 1193 |
1219 local members_only = module:require "muc/members_only"; | 1194 local members_only = module:require "muc/members_only"; |
1220 room_mt.get_members_only = members_only.get; | 1195 room_mt.get_members_only = members_only.get; |
1221 room_mt.set_members_only = members_only.set; | 1196 room_mt.set_members_only = members_only.set; |
1222 | 1197 |
1198 local persistent = module:require "muc/persistent"; | |
1199 room_mt.get_persistent = persistent.get; | |
1200 room_mt.set_persistent = persistent.set; | |
1201 | |
1223 local history = module:require "muc/history"; | 1202 local history = module:require "muc/history"; |
1224 room_mt.send_history = history.send; | 1203 room_mt.send_history = history.send; |
1225 room_mt.get_historylength = history.get_length; | 1204 room_mt.get_historylength = history.get_length; |
1226 room_mt.set_historylength = history.set_length; | 1205 room_mt.set_historylength = history.set_length; |
1227 | 1206 |