Merge 0.9->trunk
[prosody.git] / plugins / muc / mod_muc.lua
index cfb1dd2264b9518066005fa067f546583ef3bd83..9f907f172736ac063988951c436588d83a5bc1ee 100644 (file)
@@ -37,7 +37,7 @@ local rooms = rooms;
 local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {};
 
 -- Configurable options
-local max_history_messages = module:get_option_number("max_history_messages");
+muclib.set_max_history_length(module:get_option_number("max_history_messages"));
 
 local function is_admin(jid)
        return um_is_admin(jid, module.host);
@@ -50,7 +50,7 @@ function muclib.room_mt:get_affiliation(jid)
        return _get_affiliation(self, jid);
 end
 function muclib.room_mt:set_affiliation(actor, jid, affiliation, callback, reason)
-       if is_admin(jid) then return nil, "modify", "not-acceptable";; end
+       if is_admin(jid) then return nil, "modify", "not-acceptable"; end
        return _set_affiliation(self, actor, jid, affiliation, callback, reason);
 end
 
@@ -77,20 +77,22 @@ local function room_save(room, forced)
        if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
 end
 
+function create_room(jid)
+       local room = muc_new_room(jid);
+       room.route_stanza = room_route_stanza;
+       room.save = room_save;
+       rooms[jid] = room;
+       return room;
+end
+
 local persistent_errors = false;
 for jid in pairs(persistent_rooms) do
        local node = jid_split(jid);
        local data = datamanager.load(node, muc_host, "config");
        if data then
-               local room = muc_new_room(jid, {
-                       max_history_length = max_history_messages;
-               });
+               local room = create_room(jid);
                room._data = data._data;
-               room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings
                room._affiliations = data._affiliations;
-               room.route_stanza = room_route_stanza;
-               room.save = room_save;
-               rooms[jid] = room;
        else -- missing room data
                persistent_rooms[jid] = nil;
                module:log("error", "Missing data for room '%s', removing from persistent room list", jid);
@@ -99,9 +101,7 @@ for jid in pairs(persistent_rooms) do
 end
 if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end
 
-local host_room = muc_new_room(muc_host, {
-       max_history_length = max_history_messages;
-});
+local host_room = muc_new_room(muc_host);
 host_room.route_stanza = room_route_stanza;
 host_room.save = room_save;
 
@@ -126,9 +126,10 @@ local function handle_to_domain(event)
        if type == "error" or type == "result" then return; end
        if stanza.name == "iq" and type == "get" then
                local xmlns = stanza.tags[1].attr.xmlns;
-               if xmlns == "http://jabber.org/protocol/disco#info" then
+               local node = stanza.tags[1].attr.node;
+               if xmlns == "http://jabber.org/protocol/disco#info" and not node then
                        origin.send(get_disco_info(stanza));
-               elseif xmlns == "http://jabber.org/protocol/disco#items" then
+               elseif xmlns == "http://jabber.org/protocol/disco#items" and not node then
                        origin.send(get_disco_items(stanza));
                elseif xmlns == "http://jabber.org/protocol/muc#unique" then
                        origin.send(st.reply(stanza):tag("unique", {xmlns = xmlns}):text(uuid_gen())); -- FIXME Random UUIDs can theoretically have collisions
@@ -154,12 +155,7 @@ function stanza_handler(event)
                if not(restrict_room_creation) or
                  (restrict_room_creation == "admin" and is_admin(stanza.attr.from)) or
                  (restrict_room_creation == "local" and select(2, jid_split(stanza.attr.from)) == module.host:gsub("^[^%.]+%.", "")) then
-                       room = muc_new_room(bare, {
-                               max_history_length = max_history_messages;
-                       });
-                       room.route_stanza = room_route_stanza;
-                       room.save = room_save;
-                       rooms[bare] = room;
+                       room = create_room(bare);
                end
        end
        if room then
@@ -197,14 +193,11 @@ module.save = function()
 end
 module.restore = function(data)
        for jid, oldroom in pairs(data.rooms or {}) do
-               local room = muc_new_room(jid);
+               local room = create_room(jid);
                room._jid_nick = oldroom._jid_nick;
                room._occupants = oldroom._occupants;
                room._data = oldroom._data;
                room._affiliations = oldroom._affiliations;
-               room.route_stanza = room_route_stanza;
-               room.save = room_save;
-               rooms[jid] = room;
        end
        hosts[module:get_host()].muc = { rooms = rooms };
 end