Changeset

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
parents 4356:10a4f3b081a7
children 4358:86be454168fb
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon Aug 22 12:57:52 2011 -0400
+++ b/plugins/muc/muc.lib.lua	Thu Aug 25 12:05:27 2011 +0500
@@ -931,21 +931,23 @@
 	if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then
 		return nil, "modify", "not-acceptable";
 	end
-	local actor_affiliation = self:get_affiliation(actor);
-	local target_affiliation = self:get_affiliation(jid);
-	if target_affiliation == affiliation then -- no change, shortcut
-		if callback then callback(); end
-		return true;
-	end
-	if actor_affiliation ~= "owner" then
-		if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then
-			return nil, "cancel", "not-allowed";
+	if actor ~= true then
+		local actor_affiliation = self:get_affiliation(actor);
+		local target_affiliation = self:get_affiliation(jid);
+		if target_affiliation == affiliation then -- no change, shortcut
+			if callback then callback(); end
+			return true;
 		end
-	elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change
-		local is_last = true;
-		for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end
-		if is_last then
-			return nil, "cancel", "conflict";
+		if actor_affiliation ~= "owner" then
+			if actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then
+				return nil, "cancel", "not-allowed";
+			end
+		elseif target_affiliation == "owner" and jid_bare(actor) == jid then -- self change
+			local is_last = true;
+			for j, aff in pairs(self._affiliations) do if j ~= jid and aff == "owner" then is_last = false; break; end end
+			if is_last then
+				return nil, "cancel", "conflict";
+			end
 		end
 	end
 	self._affiliations[jid] = affiliation;