Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2540:8c52b023f0b9
MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 30 Jan 2010 18:51:07 +0000 |
parent | 2529:7968e8b3ecf9 |
child | 2658:a4879b1e6cde |
comparison
equal
deleted
inserted
replaced
2539:7174e6ea069d | 2540:8c52b023f0b9 |
---|---|
543 elseif _rol and not _aff then | 543 elseif _rol and not _aff then |
544 if role == "moderator" then | 544 if role == "moderator" then |
545 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? | 545 -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? |
546 if _rol == "none" then _rol = nil; end | 546 if _rol == "none" then _rol = nil; end |
547 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); | 547 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); |
548 for nick, occupant in pairs(self._occupants) do | 548 for occupant_jid, occupant in pairs(self._occupants) do |
549 if occupant.role == _rol then | 549 if occupant.role == _rol then |
550 reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); | 550 reply:tag("item", { |
551 nick = select(3, jid_split(occupant_jid)), | |
552 role = _rol or "none", | |
553 affiliation = occupant.affiliation or "none", | |
554 jid = occupant.jid | |
555 }):up(); | |
551 end | 556 end |
552 end | 557 end |
553 origin.send(reply); | 558 origin.send(reply); |
554 else | 559 else |
555 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 560 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
733 | 738 |
734 function room_mt:get_role(nick) | 739 function room_mt:get_role(nick) |
735 local session = self._occupants[nick]; | 740 local session = self._occupants[nick]; |
736 return session and session.role or nil; | 741 return session and session.role or nil; |
737 end | 742 end |
738 function room_mt:set_role(actor, nick, role, callback, reason) | 743 function room_mt:set_role(actor, occupant_jid, role, callback, reason) |
739 if role == "none" then role = nil; end | 744 if role == "none" then role = nil; end |
740 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end | 745 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end |
741 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end | 746 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
742 local occupant = self._occupants[nick]; | 747 local occupant = self._occupants[occupant_jid]; |
743 if not occupant then return nil, "modify", "not-acceptable"; end | 748 if not occupant then return nil, "modify", "not-acceptable"; end |
744 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end | 749 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end |
745 local p = st.presence({from = nick}) | 750 local p = st.presence({from = occupant_jid}) |
746 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 751 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
747 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}) | 752 :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"}) |
748 :tag("reason"):text(reason or ""):up() | 753 :tag("reason"):text(reason or ""):up() |
749 :up(); | 754 :up(); |
750 if not role then -- kick | 755 if not role then -- kick |
751 p.attr.type = "unavailable"; | 756 p.attr.type = "unavailable"; |
752 self._occupants[nick] = nil; | 757 self._occupants[occupant_jid] = nil; |
753 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick | 758 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
754 self._jid_nick[jid] = nil; | 759 self._jid_nick[jid] = nil; |
755 end | 760 end |
756 p:tag("status", {code = "307"}):up(); | 761 p:tag("status", {code = "307"}):up(); |
757 else | 762 else |
760 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick | 765 for jid in pairs(occupant.sessions) do -- send to all sessions of the nick |
761 p.attr.to = jid; | 766 p.attr.to = jid; |
762 self:_route_stanza(p); | 767 self:_route_stanza(p); |
763 end | 768 end |
764 if callback then callback(); end | 769 if callback then callback(); end |
765 self:broadcast_except_nick(p, nick); | 770 self:broadcast_except_nick(p, occupant_jid); |
766 return true; | 771 return true; |
767 end | 772 end |
768 | 773 |
769 function room_mt:_route_stanza(stanza) | 774 function room_mt:_route_stanza(stanza) |
770 local muc_child; | 775 local muc_child; |