X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=core%2Frostermanager.lua;h=e2a92696391063c72c55026e47db68d1871602e5;hb=02db59e68c9b69b848102d97db373ca2a92bdc40;hp=54c9708372c7d53c77ebb75a9a3f72f8e2b66d06;hpb=85408db9cf25894a673fd671f8102ebf103cd917;p=prosody.git diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 54c97083..e2a92696 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -1,6 +1,6 @@ -- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. @@ -18,6 +18,7 @@ local pairs, ipairs = pairs, ipairs; local tostring = tostring; local hosts = hosts; +local bare_sessions = bare_sessions; local datamanager = require "util.datamanager" local st = require "util.stanza"; @@ -81,25 +82,24 @@ function roster_push(username, host, jid) end function load_roster(username, host) - log("debug", "load_roster: asked for: "..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 - roster[username.."@"..host] = nil; - 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 {}; - roster[username.."@"..host] = nil; + if user then user.roster = roster; end + 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].events.fire_event("roster-load", username, host, roster); return roster; end @@ -114,8 +114,14 @@ function save_roster(username, host, roster) --end end if roster then - if not roster[false] then roster[false] = {}; end - roster[false].version = (roster[false].version or 0) + 1; + local metadata = roster[false]; + if not metadata then + metadata = {}; + roster[false] = metadata; + end + if metadata.version ~= true then + metadata.version = (metadata.version or 0) + 1; + end return datamanager.store(username, host, "roster", roster); end log("warn", "save_roster: user had no roster to save");