plugins/muc/muc.lib.lua

changeset 2845
f76139aa7cd5
parent 2819
49e9a8d57981
child 2864
1ce0e2ceb419
equal deleted inserted replaced
2844:0e4f6df8b2a3 2845:f76139aa7cd5
492 elseif _rol and not _aff then 492 elseif _rol and not _aff then
493 if role == "moderator" then 493 if role == "moderator" then
494 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? 494 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway?
495 if _rol == "none" then _rol = nil; end 495 if _rol == "none" then _rol = nil; end
496 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); 496 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin");
497 for nick, occupant in pairs(self._occupants) do 497 for occupant_jid, occupant in pairs(self._occupants) do
498 if occupant.role == _rol then 498 if occupant.role == _rol then
499 reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); 499 reply:tag("item", {
500 nick = select(3, jid_split(occupant_jid)),
501 role = _rol or "none",
502 affiliation = occupant.affiliation or "none",
503 jid = occupant.jid
504 }):up();
500 end 505 end
501 end 506 end
502 origin.send(reply); 507 origin.send(reply);
503 else 508 else
504 origin.send(st.error_reply(stanza, "auth", "forbidden")); 509 origin.send(st.error_reply(stanza, "auth", "forbidden"));
660 665
661 function room_mt:get_role(nick) 666 function room_mt:get_role(nick)
662 local session = self._occupants[nick]; 667 local session = self._occupants[nick];
663 return session and session.role or nil; 668 return session and session.role or nil;
664 end 669 end
665 function room_mt:set_role(actor, nick, role, callback, reason) 670 function room_mt:set_role(actor, occupant_jid, role, callback, reason)
666 if role == "none" then role = nil; end 671 if role == "none" then role = nil; end
667 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end 672 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
668 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end 673 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end
669 local occupant = self._occupants[nick]; 674 local occupant = self._occupants[occupant_jid];
670 if not occupant then return nil, "modify", "not-acceptable"; end 675 if not occupant then return nil, "modify", "not-acceptable"; end
671 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end 676 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end
672 local p = st.presence({from = nick}) 677 local p = st.presence({from = occupant_jid})
673 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) 678 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"})
674 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}) 679 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"})
675 :tag("reason"):text(reason or ""):up() 680 :tag("reason"):text(reason or ""):up()
676 :up(); 681 :up();
677 if not role then -- kick 682 if not role then -- kick
678 p.attr.type = "unavailable"; 683 p.attr.type = "unavailable";
679 self._occupants[nick] = nil; 684 self._occupants[occupant_jid] = nil;
680 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick 685 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick
681 self._jid_nick[jid] = nil; 686 self._jid_nick[jid] = nil;
682 end 687 end
683 p:tag("status", {code = "307"}):up(); 688 p:tag("status", {code = "307"}):up();
684 else 689 else
687 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick 692 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick
688 p.attr.to = jid; 693 p.attr.to = jid;
689 self:_route_stanza(p); 694 self:_route_stanza(p);
690 end 695 end
691 if callback then callback(); end 696 if callback then callback(); end
692 self:broadcast_except_nick(p, nick); 697 self:broadcast_except_nick(p, occupant_jid);
693 return true; 698 return true;
694 end 699 end
695 700
696 function room_mt:_route_stanza(stanza) 701 function room_mt:_route_stanza(stanza)
697 local muc_child; 702 local muc_child;

mercurial