MUC: Add event for when room is done being created
[prosody.git] / plugins / muc / mod_muc.lua
index fa0101b8bcbfabd145b002b5ab55f5199b57573b..c50567e911f0a7f57313805363815f38762440d8 100644 (file)
@@ -180,7 +180,7 @@ function each_room(local_only)
                        seen[room.jid] = true;
                end
                for room_jid in pairs(persistent_rooms_storage:get(nil) or {}) do
-                       if seen[room_jid] then
+                       if not seen[room_jid] then
                                local room = restore_room(room_jid);
                                if room == nil then
                                        module:log("error", "Missing data for room '%s', omitting from iteration", room_jid);
@@ -203,14 +203,14 @@ module:hook("host-disco-items", function(event)
                for room in each_room() do
                        if not room:get_hidden() then
                                local jid, room_name = room.jid, room:get_name();
-                               room_items_cache[jid] = name;
+                               room_items_cache[jid] = room_name;
                                reply:tag("item", { jid = jid, name = room_name }):up();
                        end
                end
        end
 end);
 
-module:hook("muc-room-pre-create", function(event)
+module:hook("muc-room-created", function(event)
        track_room(event.room);
 end, -1000);
 
@@ -273,6 +273,7 @@ for event_name, method in pairs {
                        -- Watch presence to create rooms
                        if stanza.attr.type == nil and stanza.name == "presence" then
                                room = muclib.new_room(room_jid);
+                               return room:handle_first_presence(origin, stanza);
                        elseif stanza.attr.type ~= "error" then
                                origin.send(st.error_reply(stanza, "cancel", "not-allowed"));
                                return true;