Merge 0.10->trunk
[prosody.git] / plugins / muc / muc.lib.lua
index 9f83af80d09f0bb13634321e1fd0b591a34807bb..60b12ac835088b0a5bb57e15ac9ae00d06fa5136 100644 (file)
@@ -187,24 +187,31 @@ end
 -- Takes the x element that goes into the stanzas
 function room_mt:publicise_occupant_status(occupant, base_x, nick, actor, reason)
        -- Build real jid and (optionally) occupant jid template presences
-       local base_presence;
-       if occupant.role ~= nil then
+       local base_presence do
                -- Try to use main jid's presence
                local pr = occupant:get_presence();
-               if pr ~= nil then
+               if pr and (pr.attr.type ~= "unavailable" or 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";};
                end
        end
-       base_presence = base_presence or st.presence {from = occupant.nick; type = "unavailable";};
 
        -- Fire event (before full_p and anon_p are created)
-       module:fire_event("muc-broadcast-presence", {
+       local event = {
                room = self; stanza = base_presence; x = base_x;
                occupant = occupant; nick = nick; actor = actor;
                reason = reason;
-       });
+       }
+       module:fire_event("muc-broadcast-presence", event);
+
+       -- Allow muc-broadcast-presence listeners to change things
+       nick = event.nick;
+       actor = event.actor;
+       reason = event.reason;
 
        local whois = self:get_whois();
+
        local actor_nick;
        if actor then
                actor_nick = select(3, jid_split(self:get_occupant_jid(actor)));
@@ -1139,7 +1146,7 @@ function room_mt:set_role(actor, occupant_jid, role, reason)
        else
                -- Can't do anything to other owners or admins
                local occupant_affiliation = self:get_affiliation(occupant.bare_jid);
-               if occupant_affiliation == "owner" and occupant_affiliation == "admin" then
+               if occupant_affiliation == "owner" or occupant_affiliation == "admin" then
                        return nil, "cancel", "not-allowed";
                end
 
@@ -1171,58 +1178,10 @@ function room_mt:set_role(actor, occupant_jid, role, reason)
        return true;
 end
 
-local affiliation_notify = module:require "muc/affiliation_notify";
-
-local name = module:require "muc/name";
-room_mt.get_name = name.get;
-room_mt.set_name = name.set;
-
-local description = module:require "muc/description";
-room_mt.get_description = description.get;
-room_mt.set_description = description.set;
-
-local hidden = module:require "muc/hidden";
-room_mt.get_hidden = hidden.get;
-room_mt.set_hidden = hidden.set;
-function room_mt:get_public()
-       return not self:get_hidden();
-end
-function room_mt:set_public(public)
-       return self:set_hidden(not public);
-end
-
-local password = module:require "muc/password";
-room_mt.get_password = password.get;
-room_mt.set_password = password.set;
-
 local whois = module:require "muc/whois";
 room_mt.get_whois = whois.get;
 room_mt.set_whois = whois.set;
 
-local members_only = module:require "muc/members_only";
-room_mt.get_members_only = members_only.get;
-room_mt.set_members_only = members_only.set;
-
-local moderated = module:require "muc/moderated";
-room_mt.get_moderated = moderated.get;
-room_mt.set_moderated = moderated.set;
-
-local persistent = module:require "muc/persistent";
-room_mt.get_persistent = persistent.get;
-room_mt.set_persistent = persistent.set;
-
-local subject = module:require "muc/subject";
-room_mt.get_changesubject = subject.get_changesubject;
-room_mt.set_changesubject = subject.set_changesubject;
-room_mt.get_subject = subject.get;
-room_mt.set_subject = subject.set;
-room_mt.send_subject = subject.send;
-
-local history = module:require "muc/history";
-room_mt.send_history = history.send;
-room_mt.get_historylength = history.get_length;
-room_mt.set_historylength = history.set_length;
-
 local _M = {}; -- module "muc"
 
 function _M.new_room(jid, config)