- -- Stanza is to this server, or a user on this server
- log("debug", "Routing stanza to local");
- handle_stanza(session, stanza);
+ if stanza.name == "presence" and origin.roster then
+ if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then
+ for jid in pairs(origin.roster) do -- broadcast to all interested contacts
+ local subscription = origin.roster[jid].subscription;
+ if subscription == "both" or subscription == "from" then
+ stanza.attr.to = jid;
+ core_route_stanza(origin, stanza);
+ end
+ end
+ --[[local node, host = jid_split(stanza.attr.from);
+ for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources
+ if res.full_jid then
+ res = user.sessions[k];
+ break;
+ end
+ end]]
+ if not origin.presence then -- presence probes on initial presence
+ local probe = st.presence({from = origin.full_jid, type = "probe"});
+ for jid in pairs(origin.roster) do
+ local subscription = origin.roster[jid].subscription;
+ if subscription == "both" or subscription == "to" then
+ probe.attr.to = jid;
+ core_route_stanza(origin, probe);
+ end
+ end
+ end
+ origin.presence = stanza;
+ stanza.attr.to = nil; -- reset it
+ else
+ -- TODO error, bad type
+ end
+ else
+ log("debug", "Routing stanza to local");
+ handle_stanza(session, stanza);
+ end