Comparison

plugins/mod_presence.lua @ 2592:3af266f7037f

mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 12 Feb 2010 00:54:14 +0500
parent 2532:b1b1b4a7db26
child 2593:06995c8bfe80
comparison
equal deleted inserted replaced
2591:d540a75a11db 2592:3af266f7037f
16 16
17 local st = require "util.stanza"; 17 local st = require "util.stanza";
18 local jid_split = require "util.jid".split; 18 local jid_split = require "util.jid".split;
19 local jid_bare = require "util.jid".bare; 19 local jid_bare = require "util.jid".bare;
20 local hosts = hosts; 20 local hosts = hosts;
21 local NULL = {};
21 22
22 local rostermanager = require "core.rostermanager"; 23 local rostermanager = require "core.rostermanager";
23 local sessionmanager = require "core.sessionmanager"; 24 local sessionmanager = require "core.sessionmanager";
24 local offlinemanager = require "core.offlinemanager"; 25 local offlinemanager = require "core.offlinemanager";
25 26
61 end 62 end
62 63
63 function handle_normal_presence(origin, stanza, core_route_stanza) 64 function handle_normal_presence(origin, stanza, core_route_stanza)
64 local roster = origin.roster; 65 local roster = origin.roster;
65 local node, host = origin.username, origin.host; 66 local node, host = origin.username, origin.host;
66 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources 67 local user = bare_sessions[node.."@"..host];
68 for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources
67 if res ~= origin and res.presence then -- to resource 69 if res ~= origin and res.presence then -- to resource
68 stanza.attr.to = res.full_jid; 70 stanza.attr.to = res.full_jid;
69 core_route_stanza(origin, stanza); 71 core_route_stanza(origin, stanza);
70 end 72 end
71 end 73 end
82 if item.subscription == "both" or item.subscription == "to" then 84 if item.subscription == "both" or item.subscription == "to" then
83 probe.attr.to = jid; 85 probe.attr.to = jid;
84 core_route_stanza(origin, probe); 86 core_route_stanza(origin, probe);
85 end 87 end
86 end 88 end
87 for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources 89 for _, res in pairs(user and user.sessions or NULL) do -- broadcast from all available resources
88 if res ~= origin and res.presence then 90 if res ~= origin and res.presence then
89 res.presence.attr.to = origin.full_jid; 91 res.presence.attr.to = origin.full_jid;
90 core_route_stanza(res, res.presence); 92 core_route_stanza(res, res.presence);
91 res.presence.attr.to = nil; 93 res.presence.attr.to = nil;
92 end 94 end