Software /
code /
verse
Changeset
228:c5a4f82e2fd6
plugins.vcard: Use util.vcard
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Nov 2011 20:04:19 +0100 |
parents | 227:31019cb93d59 |
children | 229:279c0e89c3b3 |
files | plugins/vcard.lua |
diffstat | 1 files changed, 27 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/vcard.lua Sun Nov 06 20:03:20 2011 +0100 +++ b/plugins/vcard.lua Sun Nov 06 20:04:19 2011 +0100 @@ -1,20 +1,36 @@ local xmlns_vcard = "vcard-temp"; - --- TODO Should this plugin perhaps convert to/from some non-stanza format? --- { --- FN = "Kim Alvefur"; --- NICKNAME = "Zash"; --- } +local vcard = require "util.vcard"; function verse.plugins.vcard(stream) function stream:get_vcard(jid, callback) --jid = nil for self stream:send_iq(verse.iq({to = jid, type="get"}) - :tag("vCard", {xmlns=xmlns_vcard}), callback); - end -- FIXME This should pick out the vCard element + :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza) + local lCard, xCard; + xCard = stanza:get_child("vCard", xmlns_vcard); + if stanza.attr.type == "result" and xCard then + lCard = vcard.xep54_to_lua(xCard) + vCard = vcard.xep54_to_text(xCard) + -- FIXME This is only until util.vcard.lua_to_text() is implemented + lCard._text = vCard; + callback(lCard) + else + callback(false) -- FIXME add error + end + end or nil); + end - function stream:set_vcard(vCard, callback) + function stream:set_vcard(aCard, callback) + local xCard; + if type(aCard) == "table" and aCard.name then + xCard = aCard; + elseif type(aCard) == "string" then + xCard = vcard.text_to_xep54(aCard)[1]; + elseif type(aCard) == "table" then + error("Converting a table to vCard not implemented") + end + if not xCard then return false end + stream:debug("setting vcard to %s", tostring(xCard)); stream:send_iq(verse.iq({type="set"}) - :tag("vCard", {xmlns=xmlns_vcard}) - :add_child(vCard), callback); + :add_child(xCard), callback); end end