Software /
code /
prosody
Comparison
plugins/mod_presence.lua @ 1475:16c8b1a8f6a7
mod_presence: Changed handle_normal_presence to use a local roster rather than origin's roster
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 05 Jul 2009 12:25:15 +0500 |
parent | 1474:6947761fd531 |
child | 1476:5d6199a9b4f6 |
comparison
equal
deleted
inserted
replaced
1474:6947761fd531 | 1475:16c8b1a8f6a7 |
---|---|
59 user.top_resources = select_top_resources(user); | 59 user.top_resources = select_top_resources(user); |
60 if #user.top_resources == 0 then user.top_resources = nil; end | 60 if #user.top_resources == 0 then user.top_resources = nil; end |
61 end | 61 end |
62 | 62 |
63 function handle_normal_presence(origin, stanza, core_route_stanza) | 63 function handle_normal_presence(origin, stanza, core_route_stanza) |
64 if origin.roster then | 64 local roster = origin.roster; |
65 for jid, item in pairs(origin.roster) do -- broadcast to all interested contacts | 65 if roster then |
66 for jid, item in pairs(roster) do -- broadcast to all interested contacts | |
66 if item.subscription == "both" or item.subscription == "from" then | 67 if item.subscription == "both" or item.subscription == "from" then |
67 stanza.attr.to = jid; | 68 stanza.attr.to = jid; |
68 core_route_stanza(origin, stanza); | 69 core_route_stanza(origin, stanza); |
69 end | 70 end |
70 end | 71 end |
75 core_route_stanza(origin, stanza); | 76 core_route_stanza(origin, stanza); |
76 end | 77 end |
77 end | 78 end |
78 if stanza.attr.type == nil and not origin.presence then -- initial presence | 79 if stanza.attr.type == nil and not origin.presence then -- initial presence |
79 local probe = st.presence({from = origin.full_jid, type = "probe"}); | 80 local probe = st.presence({from = origin.full_jid, type = "probe"}); |
80 for jid, item in pairs(origin.roster) do -- probe all contacts we are subscribed to | 81 for jid, item in pairs(roster) do -- probe all contacts we are subscribed to |
81 if item.subscription == "both" or item.subscription == "to" then | 82 if item.subscription == "both" or item.subscription == "to" then |
82 probe.attr.to = jid; | 83 probe.attr.to = jid; |
83 core_route_stanza(origin, probe); | 84 core_route_stanza(origin, probe); |
84 end | 85 end |
85 end | 86 end |
88 res.presence.attr.to = origin.full_jid; | 89 res.presence.attr.to = origin.full_jid; |
89 core_route_stanza(res, res.presence); | 90 core_route_stanza(res, res.presence); |
90 res.presence.attr.to = nil; | 91 res.presence.attr.to = nil; |
91 end | 92 end |
92 end | 93 end |
93 if origin.roster.pending then -- resend incoming subscription requests | 94 if roster.pending then -- resend incoming subscription requests |
94 for jid in pairs(origin.roster.pending) do | 95 for jid in pairs(roster.pending) do |
95 origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original? | 96 origin.send(st.presence({type="subscribe", from=jid})); -- TODO add to attribute? Use original? |
96 end | 97 end |
97 end | 98 end |
98 local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host}); | 99 local request = st.presence({type="subscribe", from=origin.username.."@"..origin.host}); |
99 for jid, item in pairs(origin.roster) do -- resend outgoing subscription requests | 100 for jid, item in pairs(roster) do -- resend outgoing subscription requests |
100 if item.ask then | 101 if item.ask then |
101 request.attr.to = jid; | 102 request.attr.to = jid; |
102 core_route_stanza(origin, request); | 103 core_route_stanza(origin, request); |
103 end | 104 end |
104 end | 105 end |