Software /
code /
verse
Comparison
plugins/roster.lua @ 217:60db4e738910
plugins.roster: Check stream features for roster versioning support.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 08 Sep 2011 18:04:49 +0200 |
parent | 213:aa3088108021 |
child | 250:a5ac643a7fd6 |
comparison
equal
deleted
inserted
replaced
216:3aac084855e6 | 217:60db4e738910 |
---|---|
1 local xmlns_roster = "jabber:iq:roster"; | 1 local xmlns_roster = "jabber:iq:roster"; |
2 local xmlns_rosterver = "urn:xmpp:features:rosterver"; | |
2 local bare_jid = require "util.jid".bare; | 3 local bare_jid = require "util.jid".bare; |
3 local t_insert = table.insert; | 4 local t_insert = table.insert; |
4 | 5 |
5 function verse.plugins.roster(stream) | 6 function verse.plugins.roster(stream) |
7 local ver_supported = false; | |
6 local roster = { | 8 local roster = { |
7 items = {}; | 9 items = {}; |
8 ver = ""; | 10 ver = ""; |
9 -- TODO: | 11 -- TODO: |
10 -- groups = {}; | 12 -- groups = {}; |
11 }; | 13 }; |
12 stream.roster = roster; | 14 stream.roster = roster; |
15 | |
16 stream:hook("stream-features", function(features_stanza) | |
17 if features_stanza:get_child("ver", xmlns_rosterver) then | |
18 ver_supported = true; | |
19 end | |
20 end); | |
13 | 21 |
14 local function item_lua2xml(item_table) | 22 local function item_lua2xml(item_table) |
15 local xml_item = verse.stanza("item", { xmlns = xmlns_roster }); | 23 local xml_item = verse.stanza("item", { xmlns = xmlns_roster }); |
16 for k, v in pairs(item_table) do | 24 for k, v in pairs(item_table) do |
17 if k ~= "groups" then | 25 if k ~= "groups" then |
101 roster.items[jid] = nil; | 109 roster.items[jid] = nil; |
102 return deleted_item; | 110 return deleted_item; |
103 end | 111 end |
104 | 112 |
105 function roster:fetch(callback) | 113 function roster:fetch(callback) |
106 stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster, ver = roster.ver }), | 114 stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster, ver = ver_supported and roster.ver or nil }), |
107 function (result) | 115 function (result) |
108 if result.attr.type == "result" then | 116 if result.attr.type == "result" then |
109 local query = result:get_child("query", xmlns_roster); | 117 local query = result:get_child("query", xmlns_roster); |
110 if query then | 118 if query then |
111 roster.items = {}; | 119 roster.items = {}; |