MUC: Update all config form handlers to take advantage of the new per-option events
[prosody.git] / plugins / muc / history.lib.lua
index d685abf2e11c0fcbad8c7cf6efcd7a8454e4c9f3..65b1a31f32291b813f46637524824d0eedacac18 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;
@@ -38,9 +40,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-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);