--- Prosody IM v0.3
+-- Prosody IM v0.4
-- Copyright (C) 2008-2009 Matthew Wild
-- Copyright (C) 2008-2009 Waqas Hussain
--
local format = string.format;
local loadfile, setfenv, pcall = loadfile, setfenv, pcall;
local pairs, ipairs = pairs, ipairs;
+local tostring = tostring;
local hosts = hosts;
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
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;
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
if is_contact_pending_in(username, host, jid) then
local roster = load_roster(username, host);
local item = roster[jid];
+ if not item then -- FIXME should roster item be auto-created?
+ item = {subscription = "none", groups = {}};
+ roster[jid] = item;
+ end
if item.subscription == "none" then
item.subscription = "from";
else -- subscription == to
-return _M;
\ No newline at end of file
+return _M;