Software /
code /
verse
Changeset
210:118da85cb3ce
plugins.roster: Roster versioning support.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 07 Jun 2011 20:29:54 +0200 |
parents | 209:48a404e083c4 |
children | 211:837cd09fcf01 |
files | plugins/roster.lua |
diffstat | 1 files changed, 20 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/roster.lua Tue May 24 20:22:02 2011 +0200 +++ b/plugins/roster.lua Tue Jun 07 20:29:54 2011 +0200 @@ -5,9 +5,9 @@ function verse.plugins.roster(stream) local roster = { items = {}; + ver = ""; -- TODO: -- groups = {}; - -- ver = nil; }; stream.roster = roster; @@ -43,6 +43,17 @@ return item_table; end + function roster:load(r) + roster.ver, roster.items = r.ver, r.items; + end + + function roster:dump() + return { + ver = roster.ver, + items = roster.items, + }; + end + -- should this be add_contact(item, callback) instead? function roster:add_contact(jid, nick, groups, callback) local item = { jid = jid, name = nick, groups = groups }; @@ -92,12 +103,16 @@ end function roster:fetch(callback) - stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster }), + stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster, ver = roster.ver }), function (result) if result.attr.type == "result" then local query = result:get_child("query", xmlns_roster); - for item in query:childtags("item") do - add_item(item) + if query then + roster.items = {}; + for item in query:childtags("item") do + add_item(item) + end + roster.ver = query.attr.ver or ""; end callback(roster); else @@ -123,6 +138,7 @@ add_item(item) target = roster.items[jid]; end + roster.ver = query.attr.ver; if target then stream:event("roster/item-"..event, target); end