aboutsummaryrefslogtreecommitdiffstats
path: root/core/rostermanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-03-23 00:31:29 +0000
committerMatthew Wild <mwild1@gmail.com>2009-03-23 00:31:29 +0000
commit000fa4bb34a65ae928c18be727d27b00facb5a35 (patch)
tree5a393b49f91de9f40a71f770fabcba4ce6a416a3 /core/rostermanager.lua
parent39ac97e87a619d1f52f0806125a6f1df903bd5f1 (diff)
downloadprosody-000fa4bb34a65ae928c18be727d27b00facb5a35.tar.gz
prosody-000fa4bb34a65ae928c18be727d27b00facb5a35.zip
core.rostermanager/mod_roster: Support for roster versioning
Diffstat (limited to 'core/rostermanager.lua')
-rw-r--r--core/rostermanager.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/core/rostermanager.lua b/core/rostermanager.lua
index 877d0b21..fdaf64a7 100644
--- a/core/rostermanager.lua
+++ b/core/rostermanager.lua
@@ -15,6 +15,7 @@ local setmetatable = setmetatable;
local format = string.format;
local loadfile, setfenv, pcall = loadfile, setfenv, pcall;
local pairs, ipairs = pairs, ipairs;
+local tostring = tostring;
local hosts = hosts;
@@ -54,10 +55,11 @@ function remove_from_roster(session, jid)
end
function roster_push(username, host, jid)
- if jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then
+ local roster = jid and jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster;
+ if roster then
local item = hosts[host].sessions[username].roster[jid];
local stanza = st.iq({type="set"});
- stanza:tag("query", {xmlns = "jabber:iq:roster"});
+ stanza:tag("query", {xmlns = "jabber:iq:roster", ver = tostring(roster[false].version or "1") });
if item then
stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask});
for group in pairs(item.groups) do
@@ -85,6 +87,7 @@ function load_roster(username, host)
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
hosts[host].sessions[username].roster = roster;
end
return roster;
@@ -97,8 +100,11 @@ end
function save_roster(username, host)
log("debug", "save_roster: saving roster for "..username.."@"..host);
if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then
+ local roster = hosts[host].sessions[username].roster;
+ roster[false].version = (roster[false].version or 1) + 1;
return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster);
end
+ log("warn", "save_roster: user had no roster to save");
return nil;
end
@@ -271,4 +277,4 @@ end]]
-return _M; \ No newline at end of file
+return _M;