Changeset

2049:227f3fd2caaf

rostermanager: Refactored roster loading to remove duplicate code.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 22 Oct 2009 03:46:54 +0500
parents 2048:d420722519e1
children 2050:adc1b92b8c6b
files core/rostermanager.lua
diffstat 1 files changed, 8 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/core/rostermanager.lua	Thu Oct 22 03:38:00 2009 +0500
+++ b/core/rostermanager.lua	Thu Oct 22 03:46:54 2009 +0500
@@ -83,26 +83,17 @@
 function load_roster(username, host)
 	local jid = username.."@"..host;
 	log("debug", "load_roster: asked for: "..jid);
+	local user = bare_sessions[jid];
 	local roster;
-	if hosts[host] and hosts[host].sessions[username] then
-		roster = hosts[host].sessions[username].roster;
-		if not roster then
-			log("debug", "load_roster: loading for new user: "..username.."@"..host);
-			roster = datamanager.load(username, host, "roster") or {};
-			if not roster[false] then roster[false] = { }; end
-			if roster[jid] then
-				roster[jid] = nil;
-				log("warn", "roster for "..jid.." has a self-contact");
-			end
-			hosts[host].sessions[username].roster = roster;
-			hosts[host].events.fire_event("roster-load", username, host, roster);
-		end
-		return roster;
+	if user then
+		roster = user.roster;
+		if roster then return roster; end
+		log("debug", "load_roster: loading for new user: "..username.."@"..host);
+	else -- Attempt to load roster for non-loaded user
+		log("debug", "load_roster: loading for offline user: "..username.."@"..host);
 	end
-	
-	-- Attempt to load roster for non-loaded user
-	log("debug", "load_roster: loading for offline user: "..username.."@"..host);
 	roster = datamanager.load(username, host, "roster") or {};
+	if user then user.roster = roster; end
 	if not roster[false] then roster[false] = { }; end
 	if roster[jid] then
 		roster[jid] = nil;