Annotate

plugins/roster.lua @ 224:7fc17e40fbaf

plugins.carbons: Add, implements Message Carbons (XEP 280)
author Kim Alvefur <zash@zash.se>
date Wed, 02 Nov 2011 01:17:54 +0100
parent 217:60db4e738910
child 250:a5ac643a7fd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local xmlns_roster = "jabber:iq:roster";
217
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
2 local xmlns_rosterver = "urn:xmpp:features:rosterver";
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
3 local bare_jid = require "util.jid".bare;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
4 local t_insert = table.insert;
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 function verse.plugins.roster(stream)
217
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
7 local ver_supported = false;
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
8 local roster = {
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
9 items = {};
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
10 ver = "";
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
11 -- TODO:
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
12 -- groups = {};
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
13 };
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
14 stream.roster = roster;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
15
217
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
16 stream:hook("stream-features", function(features_stanza)
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
17 if features_stanza:get_child("ver", xmlns_rosterver) then
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
18 ver_supported = true;
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
19 end
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
20 end);
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
21
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
22 local function item_lua2xml(item_table)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
23 local xml_item = verse.stanza("item", { xmlns = xmlns_roster });
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
24 for k, v in pairs(item_table) do
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
25 if k ~= "groups" then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
26 xml_item.attr[k] = v;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
27 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
28 for i = 1,#v do
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
29 xml_item:tag("group"):text(v[i]):up();
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
30 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
31 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
32 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
33 return xml_item;
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
35
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
36 local function item_xml2lua(xml_item)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
37 local item_table = { };
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
38 local groups = {};
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
39 item_table.groups = groups;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
40 local jid = xml_item.attr.jid;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
41
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
42 for k, v in pairs(xml_item.attr) do
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
43 if k ~= "xmlns" then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
44 item_table[k] = v
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
45 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
46 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
47
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
48 for group in xml_item:childtags("group") do
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
49 t_insert(groups, group:get_text())
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
50 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
51 return item_table;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
52 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
53
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
54 function roster:load(r)
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
55 roster.ver, roster.items = r.ver, r.items;
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
56 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
57
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
58 function roster:dump()
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
59 return {
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
60 ver = roster.ver,
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
61 items = roster.items,
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
62 };
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
63 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
64
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
65 -- should this be add_contact(item, callback) instead?
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
66 function roster:add_contact(jid, nick, groups, callback)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
67 local item = { jid = jid, name = nick, groups = groups };
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
68 local stanza = verse.iq({ type = "set" })
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
69 :tag("query", { xmlns = xmlns_roster })
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
70 :add_child(item_lua2xml(item));
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
71 stream:send_iq(stanza, function (reply)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
72 if not callback then return end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
73 if reply.attr.type == "result" then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
74 callback(true);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
75 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
76 type, condition, text = reply:get_error();
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
77 callback(nil, { type, condition, text });
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
78 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
79 end);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
80 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
81 -- What about subscriptions?
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
82
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
83 function roster:delete_contact(jid, callback)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
84 jid = (type(jid) == "table" and jid.jid) or jid;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
85 local item = { jid = jid, subscription = "remove" }
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
86 if not roster.items[jid] then return false, "item-not-found"; end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
87 stream:send_iq(verse.iq({ type = "set" })
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
88 :tag("query", { xmlns = xmlns_roster })
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
89 :add_child(item_lua2xml(item)),
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
90 function (reply)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
91 if not callback then return end
213
aa3088108021 plugins.roster: Fix wrong name of reply variable
Kim Alvefur <zash@zash.se>
parents: 210
diff changeset
92 if reply.attr.type == "result" then
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
93 callback(true);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
94 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
95 type, condition, text = reply:get_error();
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
96 callback(nil, { type, condition, text });
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
97 end
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 end);
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
100
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
101 local function add_item(item) -- Takes one roster <item/>
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
102 local roster_item = item_xml2lua(item);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
103 roster.items[roster_item.jid] = roster_item;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
104 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
105
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
106 -- Private low level
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
107 local function delete_item(jid)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
108 local deleted_item = roster.items[jid];
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
109 roster.items[jid] = nil;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
110 return deleted_item;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
111 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
112
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
113 function roster:fetch(callback)
217
60db4e738910 plugins.roster: Check stream features for roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 213
diff changeset
114 stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster, ver = ver_supported and roster.ver or nil }),
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
115 function (result)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
116 if result.attr.type == "result" then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
117 local query = result:get_child("query", xmlns_roster);
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
118 if query then
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
119 roster.items = {};
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
120 for item in query:childtags("item") do
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
121 add_item(item)
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
122 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
123 roster.ver = query.attr.ver or "";
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
124 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
125 callback(roster);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
126 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
127 type, condition, text = stanza:get_error();
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
128 callback(nil, { type, condition, text }); --FIXME
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
129 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
130 end);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
131 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
132
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
133 stream:hook("iq/"..xmlns_roster, function(stanza)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
134 local type, from = stanza.attr.type, stanza.attr.from;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
135 if type == "set" and (not from or from == bare_jid(stream.jid)) then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
136 local query = stanza:get_child("query", xmlns_roster);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
137 local item = query and query:get_child("item");
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
138 if item then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
139 local event, target;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
140 local jid = item.attr.jid;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
141 if item.attr.subscription == "remove" then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
142 event = "removed"
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
143 target = delete_item(jid);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
144 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
145 event = roster.items[jid] and "changed" or "added";
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
146 add_item(item)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
147 target = roster.items[jid];
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
148 end
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
149 roster.ver = query.attr.ver;
209
48a404e083c4 plugins.roster: Don't signal roster events if there was no such item
Kim Alvefur <zash@zash.se>
parents: 192
diff changeset
150 if target then
48a404e083c4 plugins.roster: Don't signal roster events if there was no such item
Kim Alvefur <zash@zash.se>
parents: 192
diff changeset
151 stream:event("roster/item-"..event, target);
48a404e083c4 plugins.roster: Don't signal roster events if there was no such item
Kim Alvefur <zash@zash.se>
parents: 192
diff changeset
152 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
153 -- TODO else return error? Events?
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
154 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
155 stream:send(verse.reply(stanza))
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
156 return true;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
157 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
158 end);
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 end