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