aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_presence.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-06-26 08:54:22 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-06-26 08:54:22 +0500
commit03164502385bf737faed58ba494670296ff852f4 (patch)
tree6f67ad7239c938e9cd2b19fae482908f932e4bf9 /plugins/mod_presence.lua
parentd9a71da2205b437903f52f517e3c6bc72eebd59a (diff)
downloadprosody-03164502385bf737faed58ba494670296ff852f4.tar.gz
prosody-03164502385bf737faed58ba494670296ff852f4.zip
mod_message, mod_presence: Maintain list of top resources. Less work in routing messages to bare JIDs. - #optimization
Diffstat (limited to 'plugins/mod_presence.lua')
-rw-r--r--plugins/mod_presence.lua35
1 files changed, 32 insertions, 3 deletions
diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua
index 62300062..80a2ecca 100644
--- a/plugins/mod_presence.lua
+++ b/plugins/mod_presence.lua
@@ -52,6 +52,29 @@ function handle_presence(origin, stanza, from_bare, to_bare, core_route_stanza,
end
end
+local function select_top_resources(user)
+ local priority = 0;
+ local recipients = {};
+ for _, session in pairs(user.sessions) do -- find resource with greatest priority
+ if session.presence then
+ -- TODO check active privacy list for session
+ local p = session.priority;
+ if p > priority then
+ priority = p;
+ recipients = {session};
+ elseif p == priority then
+ t_insert(recipients, session);
+ end
+ end
+ end
+ return recipients;
+end
+local function recalc_resource_map(origin)
+ local user = hosts[origin.host].sessions[origin.username];
+ user.top_resources = select_top_resources(user);
+ if #user.top_resources == 0 then user.top_resources = nil; end
+end
+
function handle_normal_presence(origin, stanza, core_route_stanza)
if origin.roster then
for jid in pairs(origin.roster) do -- broadcast to all interested contacts
@@ -104,9 +127,12 @@ function handle_normal_presence(origin, stanza, core_route_stanza)
offlinemanager.deleteAll(node, host);
end
end
- origin.priority = 0;
if stanza.attr.type == "unavailable" then
origin.presence = nil;
+ if origin.priority then
+ origin.priority = nil;
+ recalc_resource_map(origin);
+ end
if origin.directed then
local old_from = stanza.attr.from;
stanza.attr.from = origin.full_jid;
@@ -126,8 +152,11 @@ function handle_normal_presence(origin, stanza, core_route_stanza)
priority = tonumber(priority);
if priority < -128 then priority = -128 end
if priority > 127 then priority = 127 end
- origin.priority = priority;
- end
+ else priority = 0; end
+ else priority = 0; end
+ if origin.priority ~= priority then
+ origin.priority = priority;
+ recalc_resource_map(origin);
end
end
stanza.attr.to = nil; -- reset it