Software / code / verse
Comparison
plugins/vcard.lua @ 228:c5a4f82e2fd6
plugins.vcard: Use util.vcard
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 06 Nov 2011 20:04:19 +0100 |
| parent | 195:dc61684e8dbf |
| child | 250:a5ac643a7fd6 |
comparison
equal
deleted
inserted
replaced
| 227:31019cb93d59 | 228:c5a4f82e2fd6 |
|---|---|
| 1 local xmlns_vcard = "vcard-temp"; | 1 local xmlns_vcard = "vcard-temp"; |
| 2 | 2 local vcard = require "util.vcard"; |
| 3 -- TODO Should this plugin perhaps convert to/from some non-stanza format? | |
| 4 -- { | |
| 5 -- FN = "Kim Alvefur"; | |
| 6 -- NICKNAME = "Zash"; | |
| 7 -- } | |
| 8 | 3 |
| 9 function verse.plugins.vcard(stream) | 4 function verse.plugins.vcard(stream) |
| 10 function stream:get_vcard(jid, callback) --jid = nil for self | 5 function stream:get_vcard(jid, callback) --jid = nil for self |
| 11 stream:send_iq(verse.iq({to = jid, type="get"}) | 6 stream:send_iq(verse.iq({to = jid, type="get"}) |
| 12 :tag("vCard", {xmlns=xmlns_vcard}), callback); | 7 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza) |
| 13 end -- FIXME This should pick out the vCard element | 8 local lCard, xCard; |
| 9 xCard = stanza:get_child("vCard", xmlns_vcard); | |
| 10 if stanza.attr.type == "result" and xCard then | |
| 11 lCard = vcard.xep54_to_lua(xCard) | |
| 12 vCard = vcard.xep54_to_text(xCard) | |
| 13 -- FIXME This is only until util.vcard.lua_to_text() is implemented | |
| 14 lCard._text = vCard; | |
| 15 callback(lCard) | |
| 16 else | |
| 17 callback(false) -- FIXME add error | |
| 18 end | |
| 19 end or nil); | |
| 20 end | |
| 14 | 21 |
| 15 function stream:set_vcard(vCard, callback) | 22 function stream:set_vcard(aCard, callback) |
| 23 local xCard; | |
| 24 if type(aCard) == "table" and aCard.name then | |
| 25 xCard = aCard; | |
| 26 elseif type(aCard) == "string" then | |
| 27 xCard = vcard.text_to_xep54(aCard)[1]; | |
| 28 elseif type(aCard) == "table" then | |
| 29 error("Converting a table to vCard not implemented") | |
| 30 end | |
| 31 if not xCard then return false end | |
| 32 stream:debug("setting vcard to %s", tostring(xCard)); | |
| 16 stream:send_iq(verse.iq({type="set"}) | 33 stream:send_iq(verse.iq({type="set"}) |
| 17 :tag("vCard", {xmlns=xmlns_vcard}) | 34 :add_child(xCard), callback); |
| 18 :add_child(vCard), callback); | |
| 19 end | 35 end |
| 20 end | 36 end |