Merge 0.10->trunk
[prosody.git] / plugins / muc / lock.lib.lua
index 7cf19be3696c63b0b13b8bd98175aba69f70e59b..82f0dc3f94c0143aa462944799f1d71d28ec97c6 100644 (file)
@@ -7,6 +7,8 @@
 -- COPYING file in the source package for more information.
 --
 
+local st = require "util.stanza";
+
 local lock_rooms = module:get_option_boolean("muc_room_locking", false);
 local lock_room_timeout = module:get_option_number("muc_room_lock_timeout", 300);
 
@@ -23,7 +25,10 @@ local function is_locked(room)
 end
 
 if lock_rooms then
-       module:hook("muc-room-created", function(event)
+       module:hook("muc-room-pre-create", function(event)
+               -- Older groupchat protocol doesn't lock
+               if not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then return end
+               -- Lock room at creation
                local room = event.room;
                lock(room);
                if lock_room_timeout and lock_room_timeout > 0 then
@@ -33,16 +38,9 @@ if lock_rooms then
                                end
                        end);
                end
-       end);
+       end, 10);
 end
 
--- Older groupchat protocol doesn't lock
-module:hook("muc-room-pre-create", function(event)
-       if is_locked(event.room) and not event.stanza:get_child("x", "http://jabber.org/protocol/muc") then
-               unlock(event.room);
-       end
-end, 10);
-
 -- Don't let users into room while it is locked
 module:hook("muc-occupant-pre-join", function(event)
        if not event.is_new_room and is_locked(event.room) then -- Deny entry