-- outbound presence recieved\r
local origin, stanza = data.origin, data.stanza;\r
\r
- local t = stanza.attr.type;\r
- if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes\r
- handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);\r
- return true;\r
- end\r
-\r
local to = stanza.attr.to;\r
- local to_bare = jid_bare(to);\r
- if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence\r
- origin.directed = origin.directed or {};\r
- if t then -- removing from directed presence list on sending an error or unavailable\r
- origin.directed[to] = nil; -- FIXME does it make more sense to add to_bare rather than to?\r
- else\r
- origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to?\r
+ if to then\r
+ local t = stanza.attr.type;\r
+ if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes\r
+ handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);\r
+ return true;\r
end\r
- end\r
+\r
+ local to_bare = jid_bare(to);\r
+ if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence\r
+ origin.directed = origin.directed or {};\r
+ if t then -- removing from directed presence list on sending an error or unavailable\r
+ origin.directed[to] = nil; -- FIXME does it make more sense to add to_bare rather than to?\r
+ else\r
+ origin.directed[to] = true; -- FIXME does it make more sense to add to_bare rather than to?\r
+ end\r
+ end\r
+ end -- TODO maybe handle normal presence here, instead of letting it pass to incoming handlers?\r
end\r
\r
module:hook("pre-presence/full", outbound_presence_handler);\r
-- inbound presence to bare JID recieved\r
local origin, stanza = data.origin, data.stanza;\r
\r
- local t = stanza.attr.type;\r
- if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID\r
- handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);\r
- return true;\r
- end\r
- \r
local to = stanza.attr.to;\r
+ local t = stanza.attr.type;\r
if to then\r
+ if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID\r
+ handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza);\r
+ return true;\r
+ end\r
+ \r
local user = bare_sessions[to];\r
if user then\r
for _, session in pairs(user.sessions) do\r
end\r
end\r
end -- no resources not online, discard\r
- else\r
+ elseif not t or t == "unavailable" then\r
handle_normal_presence(origin, stanza, core_route_stanza);\r
end\r
return true;\r