Comparison

plugins/muc/muc.lib.lua @ 6105:68f53b9a186e

plugins/muc/muc: Support mediated declines
author daurnimator <quae@daurnimator.com>
date Tue, 18 Mar 2014 15:15:28 -0400
parent 6104:260a18062cb2
child 6106:4b15cfae2d11
comparison
equal deleted inserted replaced
6104:260a18062cb2 6105:68f53b9a186e
1065 origin.send(st.error_reply(stanza, "cancel", "jid-malformed")); 1065 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
1066 return true; 1066 return true;
1067 end 1067 end
1068 end 1068 end
1069 1069
1070 function room_mt:handle_mediated_decline(origin, stanza, payload)
1071 local declinee = jid_prep(payload.attr.to);
1072 if declinee then
1073 local from, to = stanza.attr.from, stanza.attr.to;
1074 -- TODO: Validate declinee
1075 local reason = payload:get_child_text("reason")
1076 local decline = st.message({from = to, to = declinee, id = stanza.attr.id})
1077 :tag('x', {xmlns='http://jabber.org/protocol/muc#user'})
1078 :tag('decline', {from=from})
1079 :tag('reason'):text(reason or ""):up()
1080 :up()
1081 :up()
1082 :tag('body') -- Add a plain message for clients which don't support declines
1083 :text(from..' declined your invite to the room '..to..(reason and (' ('..reason..')') or ""))
1084 :up();
1085 self:_route_stanza(decline);
1086 return true;
1087 else
1088 origin.send(st.error_reply(stanza, "cancel", "jid-malformed"));
1089 return true;
1090 end
1091 end
1092
1070 function room_mt:handle_message_to_room(origin, stanza) 1093 function room_mt:handle_message_to_room(origin, stanza)
1071 local type = stanza.attr.type; 1094 local type = stanza.attr.type;
1072 if type == "groupchat" then 1095 if type == "groupchat" then
1073 return self:handle_groupchat_to_room(origin, stanza) 1096 return self:handle_groupchat_to_room(origin, stanza)
1074 elseif type == "error" and is_kickable_error(stanza) then 1097 elseif type == "error" and is_kickable_error(stanza) then
1079 local payload = x.tags[1]; 1102 local payload = x.tags[1];
1080 if payload == nil then 1103 if payload == nil then
1081 -- fallthrough 1104 -- fallthrough
1082 elseif payload.name == "invite" and payload.attr.to then 1105 elseif payload.name == "invite" and payload.attr.to then
1083 return self:handle_mediated_invite(origin, stanza, payload) 1106 return self:handle_mediated_invite(origin, stanza, payload)
1107 elseif payload.name == "decline" and payload.attr.to then
1108 return self:handle_mediated_decline(origin, stanza, payload)
1084 end 1109 end
1085 origin.send(st.error_reply(stanza, "cancel", "bad-request")); 1110 origin.send(st.error_reply(stanza, "cancel", "bad-request"));
1086 return true; 1111 return true;
1087 end 1112 end
1088 else 1113 else