MUC: Assign priorities to config form hooks so they have a consistent order on each...
[prosody.git] / plugins / muc / history.lib.lua
index d685abf2e11c0fcbad8c7cf6efcd7a8454e4c9f3..437056efed974abb41e7ae60b46fa0d0e60ff3dc 100644 (file)
@@ -23,7 +23,9 @@ local function get_historylength(room)
 end
 
 local function set_historylength(room, length)
-       length = assert(tonumber(length), "Length not a valid number");
+       if length then
+               length = assert(tonumber(length), "Length not a valid number");
+       end
        if length == default_history_length then length = nil; end
        room._data.history_length = length;
        return true;
@@ -36,11 +38,10 @@ module:hook("muc-config-form", function(event)
                label = "Maximum Number of History Messages Returned by Room";
                value = tostring(get_historylength(event.room));
        });
-end);
+end, 100-10);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_historylength"];
-       if new ~= nil and set_historylength(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_historylength", function(event)
+       if set_historylength(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
@@ -78,7 +79,7 @@ end
 
 module:hook("muc-get-history", function(event)
        local room = event.room;
-       local history = room._data["history"]; -- send discussion history
+       local history = room._history; -- send discussion history
        if not history then return nil end
        local history_len = #history;
 
@@ -104,7 +105,7 @@ module:hook("muc-get-history", function(event)
        end
 
        local i = history_len-n+1
-       function event:next_stanza()
+       function event.next_stanza()
                if i > history_len then return nil end
                local entry = history[i];
                local msg = entry.stanza;
@@ -139,8 +140,8 @@ module:hook("muc-add-history", function(event)
        local historic = event.stanza:get_child("body");
        if historic then
                local room = event.room
-               local history = room._data["history"];
-               if not history then history = {}; room._data["history"] = history; end
+               local history = room._history;
+               if not history then history = {}; room._history = history; end
                local stanza = st.clone(event.stanza);
                stanza.attr.to = "";
                local ts = gettime();