Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2005:478ba7e85862
MUC: Rewrote code for mediated invites to be more robust, and to support legacy clients.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 18 Oct 2009 15:28:00 +0500 |
parent | 1999:05054e360d89 |
child | 2006:0c62bed9d338 |
comparison
equal
deleted
inserted
replaced
2004:5033348feba8 | 2005:478ba7e85862 |
---|---|
537 stanza.attr.to = to; | 537 stanza.attr.to = to; |
538 elseif type ~= "error" and type ~= "result" then | 538 elseif type ~= "error" and type ~= "result" then |
539 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 539 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
540 end | 540 end |
541 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from] | 541 elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and self._jid_nick[stanza.attr.from] |
542 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" and #stanza.tags[1].tags == 1 | 542 and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" then |
543 and stanza.tags[1].tags[1].name == "invite" and stanza.tags[1].tags[1].attr.to then | 543 local x = stanza.tags[1]; |
544 local _from, _to = stanza.attr.from, stanza.attr.to; | 544 local payload = (#x.tags == 1 and x.tags[1]); |
545 local _invitee = stanza.tags[1].tags[1].attr.to; | 545 if payload and payload.name == "invite" and payload.attr.to then |
546 stanza.attr.from, stanza.attr.to = _to, _invitee; | 546 local _from, _to = stanza.attr.from, stanza.attr.to; |
547 stanza.tags[1].tags[1].attr.from, stanza.tags[1].tags[1].attr.to = _from, nil; | 547 local _invitee = jid_prep(payload.attr.to); |
548 self:route_stanza(stanza); | 548 if _invitee then |
549 stanza.tags[1].tags[1].attr.from, stanza.tags[1].tags[1].attr.to = nil, _invitee; | 549 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1]; |
550 stanza.attr.from, stanza.attr.to = _from, _to; | 550 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
551 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) | |
552 :tag('invite', {from=_from}) | |
553 :tag('reason'):text(_reason or ""):up() | |
554 :up() | |
555 :up() | |
556 :tag('x', {xmlns="jabber:x:conference", jid=_to}) -- COMPAT: Some older clients expect this | |
557 :text(_reason or "") | |
558 :up() | |
559 :tag('body') -- Add a plain message for clients which don't support invites | |
560 :text(_from..' invited you to the room '.._to..(_reason and (' ('.._reason..')') or "")) | |
561 :up(); | |
562 self:route_stanza(invite); | |
563 else | |
564 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); | |
565 end | |
566 else | |
567 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | |
568 end | |
551 else | 569 else |
552 if type == "error" or type == "result" then return; end | 570 if type == "error" or type == "result" then return; end |
553 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 571 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
554 end | 572 end |
555 end | 573 end |