mod_storage_sql: Add method for listing stores
[prosody.git] / plugins / muc / muc.lib.lua
index 286ad70c140d43e69e6fe8554a3bef34875c2e2c..a40dc05f88baac4046e64c82d2da95beee9b1c78 100644 (file)
@@ -9,7 +9,6 @@
 local select = select;
 local pairs, ipairs = pairs, ipairs;
 
-local datamanager = require "util.datamanager";
 local datetime = require "util.datetime";
 
 local dataform = require "util.dataforms";
@@ -19,7 +18,6 @@ local jid_bare = require "util.jid".bare;
 local jid_prep = require "util.jid".prep;
 local st = require "util.stanza";
 local log = require "util.logger".init("mod_muc");
-local multitable_new = require "util.multitable".new;
 local t_insert, t_remove = table.insert, table.remove;
 local setmetatable = setmetatable;
 local base64 = require "util.encodings".base64;
@@ -133,12 +131,11 @@ function room_mt:broadcast_message(stanza, historic)
                stanza = st.clone(stanza);
                stanza.attr.to = "";
                local stamp = datetime.datetime();
-               local chars = #tostring(stanza);
                stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203
                stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
                local entry = { stanza = stanza, stamp = stamp };
                t_insert(history, entry);
-               while #history > self._data.history_length do t_remove(history, 1) end
+               while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end
        end
 end
 function room_mt:broadcast_except_nick(stanza, nick)
@@ -185,7 +182,6 @@ function room_mt:send_history(to, stanza)
 
                local n = 0;
                local charcount = 0;
-               local stanzacount = 0;
                
                for i=#history,1,-1 do
                        local entry = history[i];
@@ -340,16 +336,12 @@ function room_mt:get_changesubject()
        return self._data.changesubject;
 end
 function room_mt:get_historylength()
-       return self._data.history_length
+       return self._data.history_length or default_history_length;
 end
 function room_mt:set_historylength(length)
-       if tonumber(length) == nil then
-               return
-       end
-       length = tonumber(length);
-       log("debug", "max_history_length %s", self._data.max_history_length or "nil");
-       if self._data.max_history_length and length > self._data.max_history_length then
-               length = self._data.max_history_length
+       length = math.min(tonumber(length) or default_history_length, self._data_max_history_length or math.huge);
+       if length == default_history_length then
+               length = nil;
        end
        self._data.history_length = length;
 end
@@ -680,8 +672,8 @@ function room_mt:process_form(origin, stanza)
        dirty = dirty or (self:get_changesubject() ~= (not changesubject and true or nil))
        module:log('debug', 'changesubject=%s', changesubject and "true" or "false")
 
-       local historylength = fields['muc#roomconfig_historylength'];
-       dirty = dirty or (self:get_historylength() ~= (historylength and true or nil))
+       local historylength = tonumber(fields['muc#roomconfig_historylength']);
+       dirty = dirty or (historylength and (self:get_historylength() ~= historylength));
        module:log('debug', 'historylength=%s', historylength)
 
 
@@ -748,7 +740,11 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
        local xmlns = stanza.tags[1] and stanza.tags[1].attr.xmlns;
        if stanza.name == "iq" then
                if xmlns == "http://jabber.org/protocol/disco#info" and type == "get" then
-                       origin.send(self:get_disco_info(stanza));
+                       if stanza.tags[1].attr.node then
+                               origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented"));
+                       else
+                               origin.send(self:get_disco_info(stanza));
+                       end
                elseif xmlns == "http://jabber.org/protocol/disco#items" and type == "get" then
                        origin.send(self:get_disco_items(stanza));
                elseif xmlns == "http://jabber.org/protocol/muc#admin" then
@@ -855,13 +851,12 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
                end
        elseif stanza.name == "message" and type == "groupchat" then
                local from, to = stanza.attr.from, stanza.attr.to;
-               local room = jid_bare(to);
                local current_nick = self._jid_nick[from];
                local occupant = self._occupants[current_nick];
                if not occupant then -- not in room
                        origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
                elseif occupant.role == "visitor" then
-                       origin.send(st.error_reply(stanza, "cancel", "forbidden"));
+                       origin.send(st.error_reply(stanza, "auth", "forbidden"));
                else
                        local from = stanza.attr.from;
                        stanza.attr.from = current_nick;
@@ -872,7 +867,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha
                                        self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza
                                else
                                        stanza.attr.from = from;
-                                       origin.send(st.error_reply(stanza, "cancel", "forbidden"));
+                                       origin.send(st.error_reply(stanza, "auth", "forbidden"));
                                end
                        else
                                self:broadcast_message(stanza, self:get_historylength() > 0);