Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2006:0c62bed9d338
MUC: Added support for reason messages in role and affiliation changes (e.g., reason for kick, etc).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 18 Oct 2009 15:53:08 +0500 |
parent | 2005:478ba7e85862 |
child | 2008:6b6b924ee558 |
comparison
equal
deleted
inserted
replaced
2005:478ba7e85862 | 2006:0c62bed9d338 |
---|---|
455 end | 455 end |
456 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation | 456 if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation |
457 local occupant = self._occupants[self.jid.."/"..item.attr.nick]; | 457 local occupant = self._occupants[self.jid.."/"..item.attr.nick]; |
458 if occupant then item.attr.jid = occupant.jid; end | 458 if occupant then item.attr.jid = occupant.jid; end |
459 end | 459 end |
460 local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; | |
460 if item.attr.affiliation and item.attr.jid and not item.attr.role then | 461 if item.attr.affiliation and item.attr.jid and not item.attr.role then |
461 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); | 462 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback, reason); |
462 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | 463 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
463 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then | 464 elseif item.attr.role and item.attr.nick and not item.attr.affiliation then |
464 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback); | 465 local success, errtype, err = self:set_role(actor, self.jid.."/"..item.attr.nick, item.attr.role, callback, reason); |
465 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | 466 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
466 else | 467 else |
467 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 468 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
468 end | 469 end |
469 elseif type == "get" then | 470 elseif type == "get" then |
588 local bare = node and node.."@"..host or host; | 589 local bare = node and node.."@"..host or host; |
589 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. | 590 local result = self._affiliations[bare]; -- Affiliations are granted, revoked, and maintained based on the user's bare JID. |
590 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned | 591 if not result and self._affiliations[host] == "outcast" then result = "outcast"; end -- host banned |
591 return result; | 592 return result; |
592 end | 593 end |
593 function room_mt:set_affiliation(actor, jid, affiliation, callback) | 594 function room_mt:set_affiliation(actor, jid, affiliation, callback, reason) |
594 jid = jid_bare(jid); | 595 jid = jid_bare(jid); |
595 if affiliation == "none" then affiliation = nil; end | 596 if affiliation == "none" then affiliation = nil; end |
596 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then | 597 if affiliation and affiliation ~= "outcast" and affiliation ~= "owner" and affiliation ~= "admin" and affiliation ~= "member" then |
597 return nil, "modify", "not-acceptable"; | 598 return nil, "modify", "not-acceptable"; |
598 end | 599 end |
600 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end | 601 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end |
601 self._affiliations[jid] = affiliation; | 602 self._affiliations[jid] = affiliation; |
602 local role = self:get_default_role(affiliation); | 603 local role = self:get_default_role(affiliation); |
603 local p = st.presence() | 604 local p = st.presence() |
604 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 605 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
605 :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up(); | 606 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
607 :tag("reason"):text(reason or ""):up() | |
608 :up(); | |
606 local x = p.tags[1]; | 609 local x = p.tags[1]; |
607 local item = x.tags[1]; | 610 local item = x.tags[1]; |
608 if not role then -- getting kicked | 611 if not role then -- getting kicked |
609 p.attr.type = "unavailable"; | 612 p.attr.type = "unavailable"; |
610 if affiliation == "outcast" then | 613 if affiliation == "outcast" then |
641 | 644 |
642 function room_mt:get_role(nick) | 645 function room_mt:get_role(nick) |
643 local session = self._occupants[nick]; | 646 local session = self._occupants[nick]; |
644 return session and session.role or nil; | 647 return session and session.role or nil; |
645 end | 648 end |
646 function room_mt:set_role(actor, nick, role, callback) | 649 function room_mt:set_role(actor, nick, role, callback, reason) |
647 if role == "none" then role = nil; end | 650 if role == "none" then role = nil; end |
648 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end | 651 if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end |
649 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end | 652 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
650 local occupant = self._occupants[nick]; | 653 local occupant = self._occupants[nick]; |
651 if not occupant then return nil, "modify", "not-acceptable"; end | 654 if not occupant then return nil, "modify", "not-acceptable"; end |
652 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end | 655 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end |
653 local p = st.presence({from = nick}) | 656 local p = st.presence({from = nick}) |
654 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 657 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
655 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}):up(); | 658 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}) |
659 :tag("reason"):text(reason or ""):up() | |
660 :up(); | |
656 if not role then -- kick | 661 if not role then -- kick |
657 p.attr.type = "unavailable"; | 662 p.attr.type = "unavailable"; |
658 self._occupants[nick] = nil; | 663 self._occupants[nick] = nil; |
659 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick | 664 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
660 self._jid_nick[jid] = nil; | 665 self._jid_nick[jid] = nil; |