Comparison

plugins/mod_roster.lua @ 2908:4d9a73abb237

mod_roster: Tidier code for the roster versioning logic
author Matthew Wild <mwild1@gmail.com>
date Mon, 22 Mar 2010 01:54:22 +0000
parent 2611:c3ea4d3f857f
child 2925:692b3c6c5bd2
comparison
equal deleted inserted replaced
2905:b924d915c4d0 2908:4d9a73abb237
34 function (session, stanza) 34 function (session, stanza)
35 if stanza.tags[1].name == "query" then 35 if stanza.tags[1].name == "query" then
36 if stanza.attr.type == "get" then 36 if stanza.attr.type == "get" then
37 local roster = st.reply(stanza); 37 local roster = st.reply(stanza);
38 38
39 local ver = stanza.tags[1].attr.ver 39 local client_ver = tonumber(stanza.tags[1].attr.ver);
40 local server_ver = tonumber(session.roster[false].version or 1);
40 41
41 if (not ver) or tonumber(ver) ~= (session.roster[false].version or 1) then 42 if not (client_ver and server_ver) or client_ver ~= server_ver then
42 roster:query("jabber:iq:roster"); 43 roster:query("jabber:iq:roster");
43 -- Client does not support versioning, or has stale roster 44 -- Client does not support versioning, or has stale roster
44 for jid in pairs(session.roster) do 45 for jid in pairs(session.roster) do
45 if jid ~= "pending" and jid then 46 if jid ~= "pending" and jid then
46 roster:tag("item", { 47 roster:tag("item", {
53 roster:tag("group"):text(group):up(); 54 roster:tag("group"):text(group):up();
54 end 55 end
55 roster:up(); -- move out from item 56 roster:up(); -- move out from item
56 end 57 end
57 end 58 end
58 roster.tags[1].attr.ver = tostring(session.roster[false].version or "1"); 59 roster.tags[1].attr.ver = server_ver;
59 end 60 end
60 session.send(roster); 61 session.send(roster);
61 session.interested = true; -- resource is interested in roster updates 62 session.interested = true; -- resource is interested in roster updates
62 return true; 63 return true;
63 elseif stanza.attr.type == "set" then 64 elseif stanza.attr.type == "set" then