Comparison

plugins/muc/muc.lib.lua @ 8835:a7221ada9368

MUC: fix set_role invocation
author Jonas Wielicki <jonas@wielicki.name>
date Thu, 17 May 2018 17:11:00 +0200
parent 8795:aaff40ec7001
child 8836:564e897f0790
comparison
equal deleted inserted replaced
8834:b0093d3b2d04 8835:a7221ada9368
850 850
851 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; 851 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1];
852 if item.attr.affiliation and item.attr.jid and not item.attr.role then 852 if item.attr.affiliation and item.attr.jid and not item.attr.role then
853 jid_affiliation[item.attr.jid] = { ["affiliation"] = item.attr.affiliation, ["reason"] = reason }; 853 jid_affiliation[item.attr.jid] = { ["affiliation"] = item.attr.affiliation, ["reason"] = reason };
854 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then 854 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then
855 jidnick_role[item.attr.jid.."/"..item.attr.nick] = { ["role"] = item.attr.role, ["reason"] = reason }; 855 jidnick_role[self.jid.."/"..item.attr.nick] = { ["role"] = item.attr.role, ["reason"] = reason };
856 else 856 else
857 origin.send(st.error_reply(stanza, "cancel", "bad-request")); 857 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
858 return; 858 return;
859 end 859 end
860 end 860 end
1211 end 1211 end
1212 1212
1213 --- Checks whether the given role changes in jidnick_role can be applied by actor. 1213 --- Checks whether the given role changes in jidnick_role can be applied by actor.
1214 -- Note: Empty tables can always be applied and won't have any effect. 1214 -- Note: Empty tables can always be applied and won't have any effect.
1215 function room_mt:can_set_roles(actor, jidnick_role) 1215 function room_mt:can_set_roles(actor, jidnick_role)
1216 for jidnick, role in pairs(jidnick_role) do 1216 for jidnick, role_info in pairs(jidnick_role) do
1217 local role = role_info["role"];
1217 if role == "none" then role = nil; end 1218 if role == "none" then role = nil; end
1218 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return false, "modify", "not-acceptable"; end 1219 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return false, "modify", "not-acceptable"; end
1219 local can_set, err_type, err_condition = self:can_set_role(actor, jidnick, role) 1220 local can_set, err_type, err_condition = self:can_set_role(actor, jidnick, role)
1220 if not can_set then 1221 if not can_set then
1221 return false, err_type, err_condition; 1222 return false, err_type, err_condition;
1247 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) 1248 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"})
1248 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"}) 1249 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"})
1249 :tag("reason"):text(reason or ""):up() 1250 :tag("reason"):text(reason or ""):up()
1250 :up(); 1251 :up();
1251 local presence_type = nil; 1252 local presence_type = nil;
1252 if not role then -- kick 1253 if not role or role == "none" then -- kick
1253 presence_type = "unavailable"; 1254 presence_type = "unavailable";
1254 self._occupants[occupant_jid] = nil; 1255 self._occupants[occupant_jid] = nil;
1255 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick 1256 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
1256 self._jid_nick[jid] = nil; 1257 self._jid_nick[jid] = nil;
1257 end 1258 end
1269 p.attr.to = jid; 1270 p.attr.to = jid;
1270 self:_route_stanza(p); 1271 self:_route_stanza(p);
1271 if occupant.jid == jid then 1272 if occupant.jid == jid then
1272 bp = st.clone(p); 1273 bp = st.clone(p);
1273 bp:add_child(x); 1274 bp:add_child(x);
1274 modified_nicks[occupant_jid] = p; 1275 modified_nicks[occupant_jid] = bp;
1275 nb_modified_nicks = nb_modified_nicks + 1; 1276 nb_modified_nicks = nb_modified_nicks + 1;
1276 end 1277 end
1277 p:add_child(self_x); 1278 p:add_child(self_x);
1278 self:route_stanza(p); 1279 self:route_stanza(p);
1279 end 1280 end