- elseif stanza.name == "message" then
- print(" ...will be stored offline");
- offlinemessage.new(node, host, stanza);
- elseif stanza.name == "iq" then
- print(" ...is an iq");
- stanza.from:send(st.reply(stanza)
- :tag("error", { type = "cancel" })
- :tag("service-unavailable", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }));
- end
-end
-
--- Broadcast a presence stanza to all of a user's contacts
-function handle_stanza_presence_broadcast(session, stanza)
- if session.roster then
- local initial_presence = not session.last_presence;
- session.last_presence = stanza;
-
- -- Broadcast presence and probes
- local broadcast = st.presence({ from = session.full_jid, type = stanza.attr.type });
-
- for child in stanza:childtags() do
- broadcast:add_child(child);
- end
- for contact_jid in pairs(session.roster) do
- broadcast.attr.to = contact_jid;
- send_to(contact_jid, broadcast);
- if initial_presence then
- local node, host = jid.split(contact_jid);
- if hosts[host] and hosts[host].type == "local" then
- local contact = hosts[host].sessions[node]
- if contact then
- local pres = st.presence { to = session.full_jid };
- for resource, contact_session in pairs(contact.sessions) do
- if contact_session.last_presence then
- pres.tags = contact_session.last_presence.tags;
- pres.attr.from = contact_session.full_jid;
- send(pres);
- end
- end
+ else
+ -- user not online
+ if user_exists(node, host) then
+ if stanza.name == "presence" then
+ if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" then
+ handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza);
+ else
+ -- TODO send unavailable presence or unsubscribed
+ end
+ elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority
+ if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then
+ offlinemanager.store(node, host, stanza);
+ -- FIXME don't store messages with only chat state notifications