Changeset

2852:56630a6c9a31

mod_presence: Don't depend on user being online when calculating top resources.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 12 Feb 2010 00:55:06 +0500
parents 2851:dcd1c0a90b2f
children 2853:91143b35a755
files plugins/mod_presence.lua
diffstat 1 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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