Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6181:6baa9a59aa03
plugins/muc/muc.lib: Remove callback parameter from set_role and set_affiliation
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Fri, 28 Mar 2014 11:05:52 -0400 |
parent | 6180:35388114439f |
child | 6182:dbf0b09664cd |
comparison
equal
deleted
inserted
replaced
6180:35388114439f | 6181:6baa9a59aa03 |
---|---|
1052 elseif not item.attr.nick and item.attr.jid then | 1052 elseif not item.attr.nick and item.attr.jid then |
1053 local nick = self:get_occupant_jid(item.attr.jid); | 1053 local nick = self:get_occupant_jid(item.attr.jid); |
1054 if nick then item.attr.nick = select(3, jid_split(nick)); end | 1054 if nick then item.attr.nick = select(3, jid_split(nick)); end |
1055 end | 1055 end |
1056 local actor = stanza.attr.from; | 1056 local actor = stanza.attr.from; |
1057 local callback = function() origin.send(st.reply(stanza)); end | |
1058 local reason = item:get_child_text("reason"); | 1057 local reason = item:get_child_text("reason"); |
1058 local success, errtype, err | |
1059 if item.attr.affiliation and item.attr.jid and not item.attr.role then | 1059 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
1060 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason); | 1060 success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, reason); |
1061 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | |
1062 return true; | |
1063 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then | 1061 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
1064 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason); | 1062 success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, reason); |
1065 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | |
1066 return true; | |
1067 else | 1063 else |
1068 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 1064 success, errtype, err = nil, "cancel", "bad-request"; |
1069 return true; | 1065 end |
1070 end | 1066 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
1067 origin.send(st.reply(stanza)); | |
1068 return true; | |
1071 end | 1069 end |
1072 | 1070 |
1073 function room_mt:handle_admin_query_get_command(origin, stanza) | 1071 function room_mt:handle_admin_query_get_command(origin, stanza) |
1074 local actor = stanza.attr.from; | 1072 local actor = stanza.attr.from; |
1075 local affiliation = self:get_affiliation(actor); | 1073 local affiliation = self:get_affiliation(actor); |
1230 local invitee = stanza.attr.to | 1228 local invitee = stanza.attr.to |
1231 if room:get_members_only() and not room:get_affiliation(invitee) then | 1229 if room:get_members_only() and not room:get_affiliation(invitee) then |
1232 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from | 1230 local from = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("invite").attr.from |
1233 local current_nick = room:get_occupant_jid(from) | 1231 local current_nick = room:get_occupant_jid(from) |
1234 log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid); | 1232 log("debug", "%s invited %s into members only room %s, granting membership", from, invitee, room.jid); |
1235 room:set_affiliation(from, invitee, "member", nil, "Invited by " .. current_nick) | 1233 room:set_affiliation(from, invitee, "member", "Invited by " .. current_nick) |
1236 end | 1234 end |
1237 end); | 1235 end); |
1238 | 1236 |
1239 function room_mt:handle_mediated_decline(origin, stanza) | 1237 function room_mt:handle_mediated_decline(origin, stanza) |
1240 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline") | 1238 local payload = stanza:get_child("x", "http://jabber.org/protocol/muc#user"):get_child("decline") |
1303 local bare = node and node.."@"..host or host; | 1301 local bare = node and node.."@"..host or host; |
1304 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. | 1302 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
1305 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned | 1303 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
1306 return result; | 1304 return result; |
1307 end | 1305 end |
1308 function room_mt:set_affiliation(actor, jid, affiliation, callback, reason) | 1306 function room_mt:set_affiliation(actor, jid, affiliation, reason) |
1309 jid = jid_bare(jid); | 1307 jid = jid_bare(jid); |
1310 if affiliation == "none" then affiliation = nil; end | 1308 if affiliation == "none" then affiliation = nil; end |
1311 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then | 1309 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
1312 return nil, "modify", "not-acceptable"; | 1310 return nil, "modify", "not-acceptable"; |
1313 end | 1311 end |
1314 if actor ~= true then | 1312 if actor ~= true then |
1315 local actor_affiliation = self:get_affiliation(actor); | 1313 local actor_affiliation = self:get_affiliation(actor); |
1316 local target_affiliation = self:get_affiliation(jid); | 1314 local target_affiliation = self:get_affiliation(jid); |
1317 if target_affiliation == affiliation then -- no change, shortcut | 1315 if target_affiliation == affiliation then -- no change, shortcut |
1318 if callback then callback(); end | |
1319 return true; | 1316 return true; |
1320 end | 1317 end |
1321 if actor_affiliation ~= "owner" then | 1318 if actor_affiliation ~= "owner" then |
1322 if affiliation == "owner" or affiliation == "admin" or actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then | 1319 if affiliation == "owner" or affiliation == "admin" or actor_affiliation ~= "admin" or target_affiliation == "owner" or target_affiliation == "admin" then |
1323 return nil, "cancel", "not-allowed"; | 1320 return nil, "cancel", "not-allowed"; |
1350 end | 1347 end |
1351 for occupant in pairs(occupants_updated) do | 1348 for occupant in pairs(occupants_updated) do |
1352 self:publicise_occupant_status(occupant, x, actor, reason); | 1349 self:publicise_occupant_status(occupant, x, actor, reason); |
1353 end | 1350 end |
1354 if self.save then self:save(); end | 1351 if self.save then self:save(); end |
1355 if callback then callback(); end | |
1356 return true; | 1352 return true; |
1357 end | 1353 end |
1358 | 1354 |
1359 function room_mt:get_role(nick) | 1355 function room_mt:get_role(nick) |
1360 local occupant = self:get_occupant_by_nick(nick); | 1356 local occupant = self:get_occupant_by_nick(nick); |
1378 end | 1374 end |
1379 end | 1375 end |
1380 end | 1376 end |
1381 return nil, "cancel", "not-allowed"; | 1377 return nil, "cancel", "not-allowed"; |
1382 end | 1378 end |
1383 function room_mt:set_role(actor, occupant_jid, role, callback, reason) | 1379 function room_mt:set_role(actor, occupant_jid, role, reason) |
1384 if role == "none" then role = nil; end | 1380 if role == "none" then role = nil; end |
1385 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end | 1381 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end |
1386 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role); | 1382 local allowed, err_type, err_condition = self:can_set_role(actor, occupant_jid, role); |
1387 if not allowed then return allowed, err_type, err_condition; end | 1383 if not allowed then return allowed, err_type, err_condition; end |
1388 | 1384 |
1393 x:tag("status", {code = "307"}):up(); | 1389 x:tag("status", {code = "307"}):up(); |
1394 end | 1390 end |
1395 occupant.role = role; | 1391 occupant.role = role; |
1396 self:save_occupant(occupant); | 1392 self:save_occupant(occupant); |
1397 self:publicise_occupant_status(occupant, x, actor, reason); | 1393 self:publicise_occupant_status(occupant, x, actor, reason); |
1398 if callback then callback(); end | |
1399 return true; | 1394 return true; |
1400 end | 1395 end |
1401 | 1396 |
1402 local _M = {}; -- module "muc" | 1397 local _M = {}; -- module "muc" |
1403 | 1398 |