X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_presence.lua;h=abbc3a3da3473638f260182398162dc047a9cd2d;hb=7aa58ae9d7679f28752638a5ab7831c246b54d55;hp=3ca3b35e37684e7d21341c38f2974df1cbc3b02b;hpb=7baa83edbd77d8d0a48b244160ef33d435b7f911;p=prosody.git diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 3ca3b35e..abbc3a3d 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -29,7 +29,7 @@ function core_route_stanza(origin, stanza) if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then local node, host = jid_split(stanza.attr.to); host = hosts[host]; - if host and host.type == "local" then + if node and host and host.type == "local" then handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); return; end @@ -142,7 +142,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) stanza.attr.to = nil; -- reset it end -function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza) +function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza, stanza) local h = hosts[host]; local count = 0; if h and h.type == "local" then @@ -151,6 +151,7 @@ function send_presence_of_available_resources(user, host, jid, recipient_session for k, session in pairs(u.sessions) do local pres = session.presence; if pres then + if stanza then pres = stanza; pres.attr.from = session.full_jid; end pres.attr.to = jid; core_route_stanza(session, pres); pres.attr.to = nil; @@ -165,6 +166,7 @@ end function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) local node, host = jid_split(from_bare); + if to_bare == origin.username.."@"..origin.host then return; end -- No self contacts local st_from, st_to = stanza.attr.from, stanza.attr.to; stanza.attr.from, stanza.attr.to = from_bare, to_bare; log("debug", "outbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); @@ -218,16 +220,17 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) end else - core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); end elseif stanza.attr.type == "subscribe" then if rostermanager.is_contact_subscribed(node, host, from_bare) then - core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed -- Sending presence is not clearly stated in the RFC, but it seems appropriate if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) end else + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt if not rostermanager.is_contact_pending_in(node, host, from_bare) then if rostermanager.set_contact_pending_in(node, host, from_bare) then sessionmanager.send_to_available_resources(node, host, stanza); @@ -236,14 +239,17 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b end elseif stanza.attr.type == "unsubscribe" then if rostermanager.process_inbound_unsubscribe(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end elseif stanza.attr.type == "subscribed" then if rostermanager.process_inbound_subscription_approval(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end elseif stanza.attr.type == "unsubscribed" then if rostermanager.process_inbound_subscription_cancellation(node, host, from_bare) then + sessionmanager.send_to_interested_resources(node, host, stanza); rostermanager.roster_push(node, host, from_bare); end end -- discard any other type @@ -330,7 +336,7 @@ module:hook("resource-unbind", function(event) pres:tag("status"):text("Disconnected: "..err):up(); session:dispatch_stanza(pres); elseif session.directed then - local pres = st.presence{ type = "unavailable" }; + local pres = st.presence{ type = "unavailable", from = session.full_jid }; if not(err) or err == "closed" then err = "connection closed"; end pres:tag("status"):text("Disconnected: "..err):up(); for jid in pairs(session.directed) do