MUC: Assign priorities to config form hooks so they have a consistent order on each...
[prosody.git] / plugins / muc / subject.lib.lua
index 0b4e6fd6cf35c59c7abfb7d3e934097eb12e8df2..6f118b43f1397d1f42aeaca06df76c013d63b599 100644 (file)
@@ -25,7 +25,6 @@ local function set_changesubject(room, changesubject)
        changesubject = changesubject and true or nil;
        if get_changesubject(room) == changesubject then return false; end
        room._data.changesubject = changesubject;
-       if room.save then room:save(true); end
        return true;
 end
 
@@ -36,7 +35,7 @@ module:hook("muc-config-form", function(event)
                label = "Allow Occupants to Change Subject?";
                value = get_changesubject(event.room);
        });
-end);
+end, 100-8);
 
 module:hook("muc-config-submitted/muc#roomconfig_changesubject", function(event)
        if set_changesubject(event.room, event.value) then
@@ -61,7 +60,6 @@ local function set_subject(room, from, subject)
        if old_subject == subject and old_from == from then return false; end
        room._data.subject_from = from;
        room._data.subject = subject;
-       if room.save then room:save(); end
        local msg = create_subject_message(from, subject);
        room:broadcast_message(msg);
        return true;
@@ -78,12 +76,14 @@ module:hook("muc-occupant-groupchat", function(event)
        local stanza = event.stanza;
        local subject = stanza:get_child("subject");
        if subject then
+               local room = event.room;
                local occupant = event.occupant;
                -- Role check for subject changes
                local role_rank = valid_roles[occupant and occupant.role or "none"];
                if role_rank >= valid_roles.moderator or
-                       ( role_rank >= valid_roles.participant and get_changesubject(event.room) ) then -- and participant
-                       set_subject(event.room, occupant.nick, subject:get_text());
+                       ( role_rank >= valid_roles.participant and get_changesubject(room) ) then -- and participant
+                       set_subject(room, occupant.nick, subject:get_text());
+                       room:save();
                        return true;
                else
                        event.origin.send(st.error_reply(stanza, "auth", "forbidden"));