Mercurial > prosody-hg
comparison plugins/mod_presence.lua @ 3181:1f73b3a960cf
mod_presence: Small refactoring.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 04 Jun 2010 18:24:09 +0500 |
| parents | 89b64966f511 |
| children | a19dbb6446a0 |
comparison
equal
deleted
inserted
replaced
| 3179:99c5288a26e4 | 3181:1f73b3a960cf |
|---|---|
| 217 rostermanager.roster_push(node, host, to_bare); | 217 rostermanager.roster_push(node, host, to_bare); |
| 218 end | 218 end |
| 219 core_route_stanza(origin, stanza); | 219 core_route_stanza(origin, stanza); |
| 220 end | 220 end |
| 221 stanza.attr.from, stanza.attr.to = st_from, st_to; | 221 stanza.attr.from, stanza.attr.to = st_from, st_to; |
| 222 return true; | |
| 222 end | 223 end |
| 223 | 224 |
| 224 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) | 225 function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) |
| 225 local node, host = jid_split(to_bare); | 226 local node, host = jid_split(to_bare); |
| 226 local st_from, st_to = stanza.attr.from, stanza.attr.to; | 227 local st_from, st_to = stanza.attr.from, stanza.attr.to; |
| 266 sessionmanager.send_to_interested_resources(node, host, stanza); | 267 sessionmanager.send_to_interested_resources(node, host, stanza); |
| 267 rostermanager.roster_push(node, host, from_bare); | 268 rostermanager.roster_push(node, host, from_bare); |
| 268 end | 269 end |
| 269 end -- discard any other type | 270 end -- discard any other type |
| 270 stanza.attr.from, stanza.attr.to = st_from, st_to; | 271 stanza.attr.from, stanza.attr.to = st_from, st_to; |
| 272 return true; | |
| 271 end | 273 end |
| 272 | 274 |
| 273 local outbound_presence_handler = function(data) | 275 local outbound_presence_handler = function(data) |
| 274 -- outbound presence recieved | 276 -- outbound presence recieved |
| 275 local origin, stanza = data.origin, data.stanza; | 277 local origin, stanza = data.origin, data.stanza; |
| 276 | 278 |
| 277 local to = stanza.attr.to; | 279 local to = stanza.attr.to; |
| 278 if to then | 280 if to then |
| 279 local t = stanza.attr.type; | 281 local t = stanza.attr.type; |
| 280 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes | 282 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes |
| 281 handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); | 283 return handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
| 282 return true; | |
| 283 end | 284 end |
| 284 | 285 |
| 285 local to_bare = jid_bare(to); | 286 local to_bare = jid_bare(to); |
| 286 if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence | 287 if not(origin.roster[to_bare] and (origin.roster[to_bare].subscription == "both" or origin.roster[to_bare].subscription == "from")) then -- directed presence |
| 287 origin.directed = origin.directed or {}; | 288 origin.directed = origin.directed or {}; |
| 304 | 305 |
| 305 local to = stanza.attr.to; | 306 local to = stanza.attr.to; |
| 306 local t = stanza.attr.type; | 307 local t = stanza.attr.type; |
| 307 if to then | 308 if to then |
| 308 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID | 309 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID |
| 309 handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); | 310 return handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
| 310 return true; | |
| 311 end | 311 end |
| 312 | 312 |
| 313 local user = bare_sessions[to]; | 313 local user = bare_sessions[to]; |
| 314 if user then | 314 if user then |
| 315 for _, session in pairs(user.sessions) do | 315 for _, session in pairs(user.sessions) do |
| 327 -- inbound presence to full JID recieved | 327 -- inbound presence to full JID recieved |
| 328 local origin, stanza = data.origin, data.stanza; | 328 local origin, stanza = data.origin, data.stanza; |
| 329 | 329 |
| 330 local t = stanza.attr.type; | 330 local t = stanza.attr.type; |
| 331 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to full JID | 331 if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to full JID |
| 332 handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); | 332 return handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); |
| 333 return true; | |
| 334 end | 333 end |
| 335 | 334 |
| 336 local session = full_sessions[stanza.attr.to]; | 335 local session = full_sessions[stanza.attr.to]; |
| 337 if session then | 336 if session then |
| 338 -- TODO fire post processing event | 337 -- TODO fire post processing event |
