MUC: fix set_role invocation
authorJonas Wielicki <jonas@wielicki.name>
Thu, 17 May 2018 17:11:00 +0200
changeset 8838 a7221ada9368
parent 8837 b0093d3b2d04
child 8839 564e897f0790
MUC: fix set_role invocation
plugins/muc/muc.lib.lua
--- a/plugins/muc/muc.lib.lua	Mon May 28 21:30:32 2018 +0200
+++ b/plugins/muc/muc.lib.lua	Thu May 17 17:11:00 2018 +0200
@@ -852,7 +852,7 @@
 					if item.attr.affiliation and item.attr.jid and not item.attr.role then
 						jid_affiliation[item.attr.jid] = { ["affiliation"] = item.attr.affiliation, ["reason"] = reason };
 					elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
-						jidnick_role[item.attr.jid.."/"..item.attr.nick] = { ["role"] = item.attr.role, ["reason"] = reason };
+						jidnick_role[self.jid.."/"..item.attr.nick] = { ["role"] = item.attr.role, ["reason"] = reason };
 					else
 						origin.send(st.error_reply(stanza, "cancel", "bad-request"));
 						return;
@@ -1213,7 +1213,8 @@
 --- Checks whether the given role changes in jidnick_role can be applied by actor.
 -- Note: Empty tables can always be applied and won't have any effect.
 function room_mt:can_set_roles(actor, jidnick_role)
-	for jidnick, role in pairs(jidnick_role) do
+	for jidnick, role_info in pairs(jidnick_role) do
+		local role = role_info["role"];
 		if role == "none" then role = nil; end
 		if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return false, "modify", "not-acceptable"; end
 		local can_set, err_type, err_condition = self:can_set_role(actor, jidnick, role)
@@ -1249,7 +1250,7 @@
 					:tag("reason"):text(reason or ""):up()
 				:up();
 		local presence_type = nil;
-		if not role then -- kick
+		if not role or role == "none" then -- kick
 			presence_type = "unavailable";
 			self._occupants[occupant_jid] = nil;
 			for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
@@ -1271,7 +1272,7 @@
 			if occupant.jid == jid then
 				bp = st.clone(p);
 				bp:add_child(x);
-				modified_nicks[occupant_jid] = p;
+				modified_nicks[occupant_jid] = bp;
 				nb_modified_nicks = nb_modified_nicks + 1;
 			end
 			p:add_child(self_x);