X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_presence.lua;h=abbc3a3da3473638f260182398162dc047a9cd2d;hb=04cac3474b5d2ef6b40863e683ddb78997d739ee;hp=02ec6f7949459e6f720b674c6d8d377d70d6927f;hpb=758fe42815657bdc61dc8b0f1e7d4a39a967f47f;p=prosody.git diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 02ec6f79..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,7 +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 node == origin.username and host == origin.host then return; end -- No self contacts + 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); @@ -219,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); @@ -237,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