Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 6104:260a18062cb2
plugins/muc/muc: Rename `handle_invite_to_room` to `handle_mediated_invite`; clean up logic
author | daurnimator <quae@daurnimator.com> |
---|---|
date | Tue, 18 Mar 2014 15:15:14 -0400 |
parent | 6103:25ba4e2b31b3 |
child | 6105:68f53b9a186e |
comparison
equal
deleted
inserted
replaced
6103:25ba4e2b31b3 | 6104:260a18062cb2 |
---|---|
1029 stanza.attr.to = to; | 1029 stanza.attr.to = to; |
1030 end | 1030 end |
1031 return handled; | 1031 return handled; |
1032 end | 1032 end |
1033 | 1033 |
1034 function room_mt:handle_invite_to_room(origin, stanza, payload) | 1034 function room_mt:handle_mediated_invite(origin, stanza, payload) |
1035 local _from, _to = stanza.attr.from, stanza.attr.to; | 1035 local _from, _to = stanza.attr.from, stanza.attr.to; |
1036 if not self._jid_nick[_from] then -- Should be in room to send invite | 1036 if not self._jid_nick[_from] then -- Should be in room to send invite TODO: allow admins to send at any time |
1037 origin.send(st.error_reply(stanza, "auth", "forbidden")); | 1037 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
1038 return true; | 1038 return true; |
1039 end | 1039 end |
1040 local _invitee = jid_prep(payload.attr.to); | 1040 local _invitee = jid_prep(payload.attr.to); |
1041 if _invitee then | 1041 if _invitee then |
1042 local _reason = payload.tags[1] and payload.tags[1].name == 'reason' and #payload.tags[1].tags == 0 and payload.tags[1][1]; | 1042 local _reason = payload:get_child_text("reason") |
1043 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) | 1043 local invite = st.message({from = _to, to = _invitee, id = stanza.attr.id}) |
1044 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) | 1044 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) |
1045 :tag('invite', {from=_from}) | 1045 :tag('invite', {from=_from}) |
1046 :tag('reason'):text(_reason or ""):up() | 1046 :tag('reason'):text(_reason or ""):up() |
1047 :up(); | 1047 :up(); |
1075 return self:handle_kickable(origin, stanza) | 1075 return self:handle_kickable(origin, stanza) |
1076 elseif type == nil then | 1076 elseif type == nil then |
1077 local x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); | 1077 local x = stanza:get_child("x", "http://jabber.org/protocol/muc#user"); |
1078 if x then | 1078 if x then |
1079 local payload = x.tags[1]; | 1079 local payload = x.tags[1]; |
1080 if payload and payload.name == "invite" and payload.attr.to then | 1080 if payload == nil then |
1081 return self:handle_invite_to_room(origin, stanza, payload) | 1081 -- fallthrough |
1082 elseif payload.name == "invite" and payload.attr.to then | |
1083 return self:handle_mediated_invite(origin, stanza, payload) | |
1082 end | 1084 end |
1083 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 1085 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
1084 return true; | 1086 return true; |
1085 end | 1087 end |
1086 else | 1088 else |