Annotate

plugins/vcard.lua @ 297:447dffdaf46c

plugins.archive: Parse the timestamp
author Kim Alvefur <zash@zash.se>
date Fri, 20 Apr 2012 04:12:49 +0200
parent 250:a5ac643a7fd6
child 312:f374daa3db4d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
2 local vcard = require "util.vcard";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
3
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local xmlns_vcard = "vcard-temp";
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 function verse.plugins.vcard(stream)
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 function stream:get_vcard(jid, callback) --jid = nil for self
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 stream:send_iq(verse.iq({to = jid, type="get"})
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
9 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
10 local lCard, xCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
11 xCard = stanza:get_child("vCard", xmlns_vcard);
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
12 if stanza.attr.type == "result" and xCard then
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
13 lCard = vcard.xep54_to_lua(xCard)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
14 vCard = vcard.xep54_to_text(xCard)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
15 -- FIXME This is only until util.vcard.lua_to_text() is implemented
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
16 lCard._text = vCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
17 callback(lCard)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
18 else
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
19 callback(false) -- FIXME add error
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
20 end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
21 end or nil);
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
22 end
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
24 function stream:set_vcard(aCard, callback)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
25 local xCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
26 if type(aCard) == "table" and aCard.name then
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
27 xCard = aCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
28 elseif type(aCard) == "string" then
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
29 xCard = vcard.text_to_xep54(aCard)[1];
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
30 elseif type(aCard) == "table" then
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
31 error("Converting a table to vCard not implemented")
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
32 end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
33 if not xCard then return false end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
34 stream:debug("setting vcard to %s", tostring(xCard));
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 stream:send_iq(verse.iq({type="set"})
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
36 :add_child(xCard), callback);
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end