6 function verse.plugins.vcard(stream) |
6 function verse.plugins.vcard(stream) |
7 function stream:get_vcard(jid, callback) --jid = nil for self |
7 function stream:get_vcard(jid, callback) --jid = nil for self |
8 stream:send_iq(verse.iq({to = jid, type="get"}) |
8 stream:send_iq(verse.iq({to = jid, type="get"}) |
9 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza) |
9 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza) |
10 local lCard, xCard; |
10 local lCard, xCard; |
11 xCard = stanza:get_child("vCard", xmlns_vcard); |
11 vCard = stanza:get_child("vCard", xmlns_vcard); |
12 if stanza.attr.type == "result" and xCard then |
12 if stanza.attr.type == "result" and vCard then |
13 lCard = vcard.xep54_to_lua(xCard) |
13 vCard = vcard.from_xep54(xCard) |
14 vCard = vcard.xep54_to_text(xCard) |
14 callback(vCard) |
15 -- FIXME This is only until util.vcard.lua_to_text() is implemented |
|
16 lCard._text = vCard; |
|
17 callback(lCard) |
|
18 else |
15 else |
19 callback(false) -- FIXME add error |
16 callback(false) -- FIXME add error |
20 end |
17 end |
21 end or nil); |
18 end or nil); |
22 end |
19 end |
24 function stream:set_vcard(aCard, callback) |
21 function stream:set_vcard(aCard, callback) |
25 local xCard; |
22 local xCard; |
26 if type(aCard) == "table" and aCard.name then |
23 if type(aCard) == "table" and aCard.name then |
27 xCard = aCard; |
24 xCard = aCard; |
28 elseif type(aCard) == "string" then |
25 elseif type(aCard) == "string" then |
29 xCard = vcard.text_to_xep54(aCard)[1]; |
26 xCard = vcard.from_text(aCard)[1]; |
30 elseif type(aCard) == "table" then |
27 elseif type(aCard) == "table" then |
|
28 xCard = vcard.to_xep54(aCard); |
31 error("Converting a table to vCard not implemented") |
29 error("Converting a table to vCard not implemented") |
32 end |
30 end |
33 if not xCard then return false end |
31 if not xCard then return false end |
34 stream:debug("setting vcard to %s", tostring(xCard)); |
32 stream:debug("setting vcard to %s", tostring(xCard)); |
35 stream:send_iq(verse.iq({type="set"}) |
33 stream:send_iq(verse.iq({type="set"}) |