MUC: Update all config form handlers to take advantage of the new per-option events
authorMatthew Wild <mwild1@gmail.com>
Fri, 11 Dec 2015 15:33:58 +0000 (15:33 +0000)
committerMatthew Wild <mwild1@gmail.com>
Fri, 11 Dec 2015 15:33:58 +0000 (15:33 +0000)
plugins/muc/affiliation_notify.lib.lua
plugins/muc/description.lib.lua
plugins/muc/hidden.lib.lua
plugins/muc/history.lib.lua
plugins/muc/members_only.lib.lua
plugins/muc/moderated.lib.lua
plugins/muc/name.lib.lua
plugins/muc/password.lib.lua
plugins/muc/persistent.lib.lua
plugins/muc/subject.lib.lua
plugins/muc/whois.lib.lua

index e2ecbc3be5e994d6b5eb348c0bd5b0dddc5d7a44..0b9ab32597545e2a1468921d8008d7cdc7099e9c 100644 (file)
@@ -37,9 +37,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_affiliationnotify"];
-       if new ~= nil and set_affiliation_notify(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_affiliationnotify", function(event)
+       if set_affiliation_notify(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index 30852922f44cd7f0461f984845712bed72889784..c4b1bd093c7df86d1e060e419ae9e16426b5dd84 100644 (file)
@@ -30,9 +30,8 @@ end
 module:hook("muc-disco#info", add_form_option);
 module:hook("muc-config-form", add_form_option);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_roomdesc"];
-       if new ~= nil and set_description(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_roomdesc", function(event)
+       if set_description(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index 5ce43db8e71f11c00a990b193bea68ebe339d268..35ca302636e618226f5440958903318e338a2ca3 100644 (file)
@@ -28,9 +28,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_publicroom"];
-       if new ~= nil and set_hidden(event.room, not new) then
+module:hook("muc-config-submitted/muc#roomconfig_publicroom", function(event)
+       if set_hidden(event.room, not event.value) then
                event.status_codes["104"] = true;
        end
 end);
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);
index 90e916174837effd85106dafa62bbe349de97b8b..5e29a68d9eba821916d7f23e78212ec55457ec73 100644 (file)
@@ -61,9 +61,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_membersonly"];
-       if new ~= nil and set_members_only(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_membersonly", function(event)
+       if set_members_only(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index c375b7ada816bc14a8fe8106ceb57a9eb80ccf69..26dcb05823acdf66f0bfba1b4d9c7185b2b04ab3 100644 (file)
@@ -32,9 +32,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_moderatedroom"];
-       if new ~= nil and set_moderated(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_moderatedroom", function(event)
+       if set_moderated(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index 49d1246717899aa366be5ab63e259cd8b680617b..d9bfc4cf0f0a2315ca447ef7daaaa9c4ecf9d5de 100644 (file)
@@ -34,9 +34,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_roomname"];
-       if new ~= nil and set_name(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_roomname", function(event)
+       if set_name(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index 48486d730b57f0398a9cf1e0860e393289295d22..8c33aa9a3e376288bf6065ff2acff662f3439f68 100644 (file)
@@ -34,9 +34,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_roomsecret"];
-       if new ~= nil and set_password(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_roomsecret", function(event)
+       if set_password(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index ccf6fffe41effa35c53d87802da9ccba9e747d1d..a72bcbb54bb19354bed042a2473e63c8ce3f278a 100644 (file)
@@ -28,9 +28,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_persistentroom"];
-       if new ~= nil and set_persistent(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_persistentroom", function(event)
+       if set_persistent(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index d1895b4d51e2180f3d9e8121fae061a471a5f454..0b4e6fd6cf35c59c7abfb7d3e934097eb12e8df2 100644 (file)
@@ -38,9 +38,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_changesubject"];
-       if new ~= nil and set_changesubject(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_changesubject", function(event)
+       if set_changesubject(event.room, event.value) then
                event.status_codes["104"] = true;
        end
 end);
index f89e60876fadd4e6bf09986a5cadeb8a8a23ec2a..a8e1f8d419bd0c89591e0b11dfa72633bc690692 100644 (file)
@@ -41,9 +41,8 @@ module:hook("muc-config-form", function(event)
        });
 end);
 
-module:hook("muc-config-submitted", function(event)
-       local new = event.fields["muc#roomconfig_whois"];
-       if new ~= nil and set_whois(event.room, new) then
+module:hook("muc-config-submitted/muc#roomconfig_whois", function(event)
+       if set_whois(event.room, event.value) then
                local code = (new == 'moderators') and "173" or "172";
                event.status_codes[code] = true;
        end