local r = rooms:get(room);
if r then
for occupant, o_data in pairs(r) do
- if occupant ~= from then
+ if occupant ~= to then
local pres = get_filtered_presence(o_data.sessions[o_data.jid]);
pres.attr.to, pres.attr.from = from, occupant;
pres
elseif type ~= 'result' then -- bad type
origin.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME correct error?
end
- elseif stanza.name == "message" and type == "groupchat" then
- -- groupchat messages not allowed in PM
+ elseif not current_nick then -- not in room
+ origin.send(st.error_reply(stanza, "cancel", "not-acceptable"));
+ elseif stanza.name == "message" and type == "groupchat" then -- groupchat messages not allowed in PM
origin.send(st.error_reply(stanza, "modify", "bad-request"));
- else
- origin.send(st.error_reply(stanza, "cancel", "not-implemented", "Private stanzas not implemented")); -- TODO route private stanza
+ elseif stanza.name == "message" and type == "error" then
+ if current_nick then
+ local data = rooms:get(room, to);
+ data.role = 'none';
+ local pr = st.presence({type='unavailable', from=current_nick}):tag('status'):text('This participant is kicked from the room because he sent an error message to another occupant'):up()
+ :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
+ :tag("item", {affiliation=data.affiliation, role=data.role}):up();
+ broadcast_presence_stanza(room, pr);
+ rooms:remove(room, to);
+ jid_nick:remove(from, room);
+ end
+ else -- private stanza
+ local o_data = rooms:get(room, to);
+ if o_data then
+ local jid = o_data.jid;
+ if stanza.name=='iq' and type=='get' and stanza.tags[1].attr.xmlns == 'vcard-temp' then jid = jid_bare(jid); end
+ stanza.attr.to, stanza.attr.from = jid, current_nick;
+ core_route_stanza(component, stanza);
+ else -- recipient not in room
+ origin.send(st.error_reply(stanza, "cancel", "item-not-found", "Recipient not in room"));
+ end
end
end