Annotate

plugins/roster.lua @ 210:118da85cb3ce

plugins.roster: Roster versioning support.
author Kim Alvefur <zash@zash.se>
date Tue, 07 Jun 2011 20:29:54 +0200
parent 209:48a404e083c4
child 213:aa3088108021
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";
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
2 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
3 local t_insert = table.insert;
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 function verse.plugins.roster(stream)
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
6 local roster = {
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
7 items = {};
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
8 ver = "";
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
9 -- TODO:
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
10 -- groups = {};
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
11 };
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
12 stream.roster = roster;
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 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
15 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
16 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
17 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
18 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
19 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
20 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
21 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
22 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
23 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
24 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
25 return xml_item;
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
27
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
28 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
29 local item_table = { };
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
30 local groups = {};
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
31 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
32 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
33
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
34 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
35 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
36 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
37 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
38 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
39
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
40 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
41 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
42 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
43 return item_table;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
44 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
45
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
46 function roster:load(r)
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
47 roster.ver, roster.items = r.ver, r.items;
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
48 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
49
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
50 function roster:dump()
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
51 return {
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
52 ver = roster.ver,
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
53 items = roster.items,
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
54 };
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
55 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
56
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
57 -- 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
58 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
59 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
60 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
61 :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
62 :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
63 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
64 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
65 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
66 callback(true);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
67 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
68 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
69 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
70 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
71 end);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
72 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
73 -- What about subscriptions?
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
74
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
75 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
76 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
77 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
78 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
79 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
80 :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
81 :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
82 function (reply)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
83 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
84 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
85 callback(true);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
86 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
87 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
88 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
89 end
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 end);
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
92
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
93 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
94 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
95 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
96 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
97
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
98 -- Private low level
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
99 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
100 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
101 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
102 return deleted_item;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
103 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
104
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
105 function roster:fetch(callback)
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
106 stream:send_iq(verse.iq({type="get"}):tag("query", { xmlns = xmlns_roster, ver = roster.ver }),
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
107 function (result)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
108 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
109 local query = result:get_child("query", xmlns_roster);
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
110 if query then
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
111 roster.items = {};
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
112 for item in query:childtags("item") do
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
113 add_item(item)
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
114 end
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
115 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
116 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
117 callback(roster);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
118 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
119 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
120 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
121 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
122 end);
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
123 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
124
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
125 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
126 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
127 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
128 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
129 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
130 if item then
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
131 local event, target;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
132 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
133 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
134 event = "removed"
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
135 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
136 else
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
137 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
138 add_item(item)
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
139 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
140 end
210
118da85cb3ce plugins.roster: Roster versioning support.
Kim Alvefur <zash@zash.se>
parents: 209
diff changeset
141 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
142 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
143 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
144 end
192
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
145 -- 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
146 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
147 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
148 return true;
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
149 end
d20feb8034f5 plugins.roster: Add roster push handling, roster item parsing, delete_contact()
Kim Alvefur <zash@zash.se>
parents: 82
diff changeset
150 end);
82
f306c2f8bb88 plugins.roster: Unfinished roster plugin
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 end