# HG changeset patch # User Waqas Hussain # Date 1224792414 -18000 # Node ID 6b8e2bd82ac5e9a432b0de575a50d09be2fdc4d9 # Parent 096c7b9374fc79bd89c13ba02a48a9b0bb5df72d Moved some code and removed unnecessary checks. diff -r 096c7b9374fc -r 6b8e2bd82ac5 core/stanza_router.lua --- a/core/stanza_router.lua Fri Oct 24 00:26:01 2008 +0500 +++ b/core/stanza_router.lua Fri Oct 24 01:06:54 2008 +0500 @@ -56,7 +56,7 @@ local session = origin; if stanza.name == "presence" and origin.roster then - if stanza.attr.type == nil or stanza.attr.type == "available" or stanza.attr.type == "unavailable" then + if stanza.attr.type == nil 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 @@ -65,28 +65,28 @@ end end local node, host = jid_split(stanza.attr.from); - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources and from resources - if res ~= origin then - if res.full_jid then -- to resource. FIXME is this check correct? Maybe it should be res.presence - stanza.attr.to = res.full_jid; - core_route_stanza(origin, stanza); - end - if res.presence then -- from all resources for which we have presence - res.presence.attr.to = origin.full_jid; - core_route_stanza(res, res.presence); - res.presence.attr.to = nil; - end + for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources + if res ~= origin and res.full_jid then -- to resource. FIXME is res.full_jid the correct check? Maybe it should be res.presence + stanza.attr.to = res.full_jid; + core_route_stanza(origin, stanza); 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 + for jid in pairs(origin.roster) do -- probe all contacts we are subscribed to local subscription = origin.roster[jid].subscription; if subscription == "both" or subscription == "to" then probe.attr.to = jid; core_route_stanza(origin, probe); end end + for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all resources + if res ~= origin and stanza.attr.type ~= "unavailable" and res.presence then -- FIXME does unavailable qualify as initial presence? + res.presence.attr.to = origin.full_jid; + core_route_stanza(res, res.presence); + res.presence.attr.to = nil; + end + end -- TODO resend subscription requests end origin.presence = stanza;