- if sessions then
- -- some resources are online
- -- TODO find top resources willing to accept this message
- -- TODO then send them each the stanza
- else
+ local t = stanza.attr.type;
+ if t == "error" then
+ -- discard
+ elseif t == "groupchat" then
+ origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
+ elseif t == "headline" then
+ if user and stanza.attr.to == bare then
+ for _, session in pairs(user.sessions) do
+ if session.presence and session.priority >= 0 then
+ session.send(stanza);
+ end
+ end
+ end -- current policy is to discard headlines if no recipient is available
+ else -- chat or normal message
+ if user then -- some resources are connected
+ local recipients = user.top_resources;
+ if recipients then
+ for i=1,#recipients do
+ recipients[i].send(stanza);
+ end
+ return true;
+ end
+ end