11 local rostermanager = require "core.rostermanager"; |
11 local rostermanager = require "core.rostermanager"; |
12 local sessionmanager = require "core.sessionmanager"; |
12 local sessionmanager = require "core.sessionmanager"; |
13 |
13 |
14 module "presencemanager" |
14 module "presencemanager" |
15 |
15 |
16 function send_presence_of_available_resources(user, host, jid, recipient_session) |
16 function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza) |
17 local h = hosts[host]; |
17 local h = hosts[host]; |
18 local count = 0; |
18 local count = 0; |
19 if h and h.type == "local" then |
19 if h and h.type == "local" then |
20 local u = h.sessions[user]; |
20 local u = h.sessions[user]; |
21 if u then |
21 if u then |
22 for k, session in pairs(u.sessions) do |
22 for k, session in pairs(u.sessions) do |
23 local pres = session.presence; |
23 local pres = session.presence; |
24 if pres then |
24 if pres then |
25 pres.attr.to = jid; |
25 pres.attr.to = jid; |
26 pres.attr.from = session.full_jid; |
26 pres.attr.from = session.full_jid; |
27 recipient_session.send(pres); |
27 core_route_stanza(recipient_session, pres); |
28 pres.attr.to = nil; |
28 pres.attr.to = nil; |
29 pres.attr.from = nil; |
29 pres.attr.from = nil; |
30 count = count + 1; |
30 count = count + 1; |
31 end |
31 end |
32 end |
32 end |
59 -- 2. roster_push () |
59 -- 2. roster_push () |
60 -- 3. send_presence_of_available_resources |
60 -- 3. send_presence_of_available_resources |
61 if rostermanager.subscribed(node, host, to_bare) then |
61 if rostermanager.subscribed(node, host, to_bare) then |
62 rostermanager.roster_push(node, host, to_bare); |
62 rostermanager.roster_push(node, host, to_bare); |
63 core_route_stanza(origin, stanza); |
63 core_route_stanza(origin, stanza); |
64 send_presence_of_available_resources(node, host, to_bare, origin); |
64 send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza); |
65 end |
65 end |
66 elseif stanza.attr.type == "unsubscribed" then |
66 elseif stanza.attr.type == "unsubscribed" then |
67 -- 1. route stanza |
67 -- 1. route stanza |
68 -- 2. roster push (subscription = none or to) |
68 -- 2. roster push (subscription = none or to) |
69 if rostermanager.unsubscribed(node, host, to_bare) then |
69 if rostermanager.unsubscribed(node, host, to_bare) then |
79 local st_from, st_to = stanza.attr.from, stanza.attr.to; |
79 local st_from, st_to = stanza.attr.from, stanza.attr.to; |
80 stanza.attr.from, stanza.attr.to = from_bare, to_bare; |
80 stanza.attr.from, stanza.attr.to = from_bare, to_bare; |
81 log("debug", "inbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); |
81 log("debug", "inbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); |
82 if stanza.attr.type == "probe" then |
82 if stanza.attr.type == "probe" then |
83 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
83 if rostermanager.is_contact_subscribed(node, host, from_bare) then |
84 if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then |
84 if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then |
85 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
85 -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) |
86 end |
86 end |
87 else |
87 else |
88 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); |
88 core_route_stanza(origin, st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); |
89 end |
89 end |