Comparison

plugins/muc/muc.lib.lua @ 4357:d6928b78c548

MUC: Allow affiliation change when argument actor==true in room:set_affiliation().
author Waqas Hussain <waqas20@gmail.com>
date Thu, 25 Aug 2011 12:05:27 +0500
parent 4326:6c082bf9bf0f
child 4424:1cbf3744300c
comparison
equal deleted inserted replaced
4356:10a4f3b081a7 4357:d6928b78c548
929 jid = jid_bare(jid); 929 jid = jid_bare(jid);
930 if affiliation == "none" then affiliation = nil; end 930 if affiliation == "none" then affiliation = nil; end
931 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then 931 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then
932 return nil, "modify", "not-acceptable"; 932 return nil, "modify", "not-acceptable";
933 end 933 end
934 local actor_affiliation = self:get_affiliation(actor); 934 if actor ~= true then
935 local target_affiliation = self:get_affiliation(jid); 935 local actor_affiliation = self:get_affiliation(actor);
936 if target_affiliation == affiliation then -- no change, shortcut 936 local target_affiliation = self:get_affiliation(jid);
937 if callback then callback(); end 937 if target_affiliation == affiliation then -- no change, shortcut
938 return true; 938 if callback then callback(); end
939 end 939 return true;
940 if actor_affiliation ~= "owner" then 940 end
941 if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then 941 if actor_affiliation ~= "owner" then
942 return nil, "cancel", "not-allowed"; 942 if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then
943 end 943 return nil, "cancel", "not-allowed";
944 elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change 944 end
945 local is_last = true; 945 elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change
946 for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end 946 local is_last = true;
947 if is_last then 947 for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end
948 return nil, "cancel", "conflict"; 948 if is_last then
949 return nil, "cancel", "conflict";
950 end
949 end 951 end
950 end 952 end
951 self._affiliations[jid] = affiliation; 953 self._affiliations[jid] = affiliation;
952 local role = self:get_default_role(affiliation); 954 local role = self:get_default_role(affiliation);
953 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) 955 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})