Comparison

plugins/muc/muc.lib.lua @ 3279:8b0a4a7d2c6e

MUC: Added room:can_set_role().
author Waqas Hussain <waqas20@gmail.com>
date Sat, 19 Jun 2010 23:35:53 +0500
parent 3264:e1c787c6f86e
child 3280:eef4f31f2d7b
comparison
equal deleted inserted replaced
3278:5ca2ed58788f 3279:8b0a4a7d2c6e
879 879
880 function room_mt:get_role(nick) 880 function room_mt:get_role(nick)
881 local session = self._occupants[nick]; 881 local session = self._occupants[nick];
882 return session and session.role or nil; 882 return session and session.role or nil;
883 end 883 end
884 function room_mt:can_set_role(actor_jid, occupant_jid, role)
885 local actor = self._occupants[self._jid_nick[actor_jid]];
886 local occupant = self._occupants[occupant_jid];
887
888 if not occupant or not actor then return nil, "modify", "not-acceptable"; end
889
890 if actor.role == "moderator" then
891 if occupant.affiliation ~= "owner" and occupant.affiliation ~= "admin" then
892 if actor.affiliation == "owner" or actor.affiliation == "admin" then
893 return true;
894 elseif occupant.role ~= "moderator" and role ~= "moderator" then
895 return true;
896 end
897 end
898 end
899 return nil, "cancel", "not-allowed";
900 end
884 function room_mt:set_role(actor, occupant_jid, role, callback, reason) 901 function room_mt:set_role(actor, occupant_jid, role, callback, reason)
885 if role == "none" then role = nil; end 902 if role == "none" then role = nil; end
886 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end 903 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
887 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end 904 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end
888 local occupant = self._occupants[occupant_jid]; 905 local occupant = self._occupants[occupant_jid];