Software /
code /
prosody
Changeset
5808:026367992a0f
mod_muc: Support for locking newly-created rooms until they are configured (enabled with muc_room_locking = true)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 30 Aug 2013 14:15:29 +0100 |
parents | 5807:d7212bd61b60 |
children | 5809:be997c6a69be |
files | plugins/muc/mod_muc.lua plugins/muc/muc.lib.lua |
diffstat | 2 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua Fri Aug 30 14:10:51 2013 +0100 +++ b/plugins/muc/mod_muc.lua Fri Aug 30 14:15:29 2013 +0100 @@ -23,6 +23,9 @@ restrict_room_creation = nil; end end +local lock_rooms = module:get_option_boolean("muc_room_locking", false); +local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300); + local muclib = module:require "muc"; local muc_new_room = muclib.new_room; local jid_split = require "util.jid".split; @@ -88,6 +91,16 @@ room.route_stanza = room_route_stanza; room.save = room_save; rooms[jid] = room; + if lock_rooms then + room.locked = true; + if lock_room_timeout and lock_room_timeout > 0 then + module:add_timer(lock_room_timeout, function () + if room.locked then + room:destroy(); -- Not unlocked in time + end + end); + end + end module:fire_event("muc-room-created", { room = room }); return room; end
--- a/plugins/muc/muc.lib.lua Fri Aug 30 14:10:51 2013 +0100 +++ b/plugins/muc/muc.lib.lua Fri Aug 30 14:15:29 2013 +0100 @@ -480,6 +480,12 @@ log("debug", "%s joining as %s", from, to); if not next(self._affiliations) then -- new room, no owners self._affiliations[jid_bare(from)] = "owner"; + if self.locked and not stanza:get_child("x", "http://jabber.org/protocol/muc") then + self.locked = nil; -- Older groupchat protocol doesn't lock + end + elseif self.locked then -- Deny entry + origin.send(st.error_reply(stanza, "cancel", "item-not-found")); + return; end local affiliation = self:get_affiliation(from); local role = self:get_default_role(affiliation) @@ -501,6 +507,9 @@ if self._data.whois == 'anyone' then pr:tag("status", {code='100'}):up(); end + if self.locked then + pr:tag("status", {code='201'}):up(); + end pr.attr.to = from; self:_route_stanza(pr); self:send_history(from, stanza); @@ -688,6 +697,10 @@ handle_option("password", "muc#roomconfig_roomsecret"); if self.save then self:save(true); end + if self.locked then + module:fire_event("muc-room-unlocked", { room = self }); + self.locked = nil; + end origin.send(st.reply(stanza)); if next(changed) then