# HG changeset patch # User Waqas Hussain # Date 1265918106 -18000 # Node ID 56630a6c9a3107a8044dff0c191aaa4b058a738d # Parent dcd1c0a90b2f42dc952781d61e8cc8834ce64174 mod_presence: Don't depend on user being online when calculating top resources. diff -r dcd1c0a90b2f -r 56630a6c9a31 plugins/mod_presence.lua --- a/plugins/mod_presence.lua Fri Feb 12 00:54:14 2010 +0500 +++ b/plugins/mod_presence.lua Fri Feb 12 00:55:06 2010 +0500 @@ -55,10 +55,11 @@ 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 +local function recalc_resource_map(user) + if user then + user.top_resources = select_top_resources(user); + if #user.top_resources == 0 then user.top_resources = nil; end + end end function handle_normal_presence(origin, stanza, core_route_stanza) @@ -117,7 +118,7 @@ origin.presence = nil; if origin.priority then origin.priority = nil; - recalc_resource_map(origin); + recalc_resource_map(user); end if origin.directed then for jid in pairs(origin.directed) do @@ -139,7 +140,7 @@ else priority = 0; end if origin.priority ~= priority then origin.priority = priority; - recalc_resource_map(origin); + recalc_resource_map(user); end end stanza.attr.to = nil; -- reset it