Software /
code /
prosody
Comparison
core/rostermanager.lua @ 916:f0743928ef7e
core.rostermanager/mod_roster: Support for roster versioning
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Mar 2009 00:31:29 +0000 |
parent | 896:2c0b9e3c11c3 |
child | 925:4861bcf0afa4 |
comparison
equal
deleted
inserted
replaced
915:0fe5bf7ab81d | 916:f0743928ef7e |
---|---|
13 | 13 |
14 local setmetatable = setmetatable; | 14 local setmetatable = setmetatable; |
15 local format = string.format; | 15 local format = string.format; |
16 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; | 16 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; |
17 local pairs, ipairs = pairs, ipairs; | 17 local pairs, ipairs = pairs, ipairs; |
18 local tostring = tostring; | |
18 | 19 |
19 local hosts = hosts; | 20 local hosts = hosts; |
20 | 21 |
21 local datamanager = require "util.datamanager" | 22 local datamanager = require "util.datamanager" |
22 local st = require "util.stanza"; | 23 local st = require "util.stanza"; |
52 return nil, "auth", "not-authorized", "Session's roster not loaded"; | 53 return nil, "auth", "not-authorized", "Session's roster not loaded"; |
53 end | 54 end |
54 end | 55 end |
55 | 56 |
56 function roster_push(username, host, jid) | 57 function roster_push(username, host, jid) |
57 if jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 58 local roster = jid and jid ~= "pending" and hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster; |
59 if roster then | |
58 local item = hosts[host].sessions[username].roster[jid]; | 60 local item = hosts[host].sessions[username].roster[jid]; |
59 local stanza = st.iq({type="set"}); | 61 local stanza = st.iq({type="set"}); |
60 stanza:tag("query", {xmlns = "jabber:iq:roster"}); | 62 stanza:tag("query", {xmlns = "jabber:iq:roster", ver = tostring(roster[false].version or "1") }); |
61 if item then | 63 if item then |
62 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); | 64 stanza:tag("item", {jid = jid, subscription = item.subscription, name = item.name, ask = item.ask}); |
63 for group in pairs(item.groups) do | 65 for group in pairs(item.groups) do |
64 stanza:tag("group"):text(group):up(); | 66 stanza:tag("group"):text(group):up(); |
65 end | 67 end |
83 if hosts[host] and hosts[host].sessions[username] then | 85 if hosts[host] and hosts[host].sessions[username] then |
84 local roster = hosts[host].sessions[username].roster; | 86 local roster = hosts[host].sessions[username].roster; |
85 if not roster then | 87 if not roster then |
86 log("debug", "load_roster: loading for new user: "..username.."@"..host); | 88 log("debug", "load_roster: loading for new user: "..username.."@"..host); |
87 roster = datamanager.load(username, host, "roster") or {}; | 89 roster = datamanager.load(username, host, "roster") or {}; |
90 if not roster[false] then roster[false] = { }; end | |
88 hosts[host].sessions[username].roster = roster; | 91 hosts[host].sessions[username].roster = roster; |
89 end | 92 end |
90 return roster; | 93 return roster; |
91 end | 94 end |
92 -- Attempt to load roster for non-loaded user | 95 -- Attempt to load roster for non-loaded user |
95 end | 98 end |
96 | 99 |
97 function save_roster(username, host) | 100 function save_roster(username, host) |
98 log("debug", "save_roster: saving roster for "..username.."@"..host); | 101 log("debug", "save_roster: saving roster for "..username.."@"..host); |
99 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then | 102 if hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster then |
103 local roster = hosts[host].sessions[username].roster; | |
104 roster[false].version = (roster[false].version or 1) + 1; | |
100 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); | 105 return datamanager.store(username, host, "roster", hosts[host].sessions[username].roster); |
101 end | 106 end |
107 log("warn", "save_roster: user had no roster to save"); | |
102 return nil; | 108 return nil; |
103 end | 109 end |
104 | 110 |
105 function process_inbound_subscription_approval(username, host, jid) | 111 function process_inbound_subscription_approval(username, host, jid) |
106 local roster = load_roster(username, host); | 112 local roster = load_roster(username, host); |