MUC: Don't force-save rooms where not needed
[prosody.git] / plugins / muc / muc.lib.lua
index 470d199e4e366c24d872266bdd61608c89dd8d5f..14aad42c329d7cca1db896c92924f26d85af56f9 100644 (file)
@@ -196,7 +196,7 @@ function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason
        local base_presence do
                -- Try to use main jid's presence
                local pr = occupant:get_presence();
-               if pr and (pr.attr.type ~= "unavailable" or occupant.role == nil) then
+               if pr and (pr.attr.type ~= "unavailable" and occupant.role ~= nil) then
                        base_presence = st.clone(pr);
                else -- user is leaving but didn't send a leave presence. make one for them
                        base_presence = st.presence {from = occupant.nick; type = "unavailable";};
@@ -709,7 +709,7 @@ function room_mt:process_form(origin, stanza)
                end
                event.field, event.value = nil, nil;
 
-               self:save(true);
+               self:save();
                origin.send(st.reply(stanza));
 
                if next(event.status_codes) then
@@ -737,7 +737,6 @@ function room_mt:clear(x)
                occupants_updated[occupant] = true;
        end
        for occupant in pairs(occupants_updated) do
-               occupant:set_session(occupant.jid, st.presence({type="unavailable"}), true);
                self:publicise_occupant_status(occupant, x);
                module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;});
        end
@@ -1160,7 +1159,7 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason)
                end
        end
 
-       self:save(true);
+       self:save();
 
        module:fire_event("muc-set-affiliation", {
                room = self;
@@ -1184,7 +1183,7 @@ function room_mt:set_role(actor, occupant_jid, role, reason)
        if not actor then return nil, "modify", "not-acceptable"; end
 
        local occupant = self:get_occupant_by_nick(occupant_jid);
-       if not occupant then return nil, "modify", "not-acceptable"; end
+       if not occupant then return nil, "modify", "item-not-found"; end
 
        if valid_roles[role or "none"] == nil then
                return nil, "modify", "not-acceptable";