plugins/mod_presence.lua

changeset 2851
dcd1c0a90b2f
parent 2844
0e4f6df8b2a3
child 2593
06995c8bfe80
equal deleted inserted replaced
2850:3f646804ed6a 2851:dcd1c0a90b2f
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

mercurial