Software /
code /
verse
Annotate
plugins/vcard.lua @ 289:8bbe0d6dfd11
plugins.jingle_s5b: Add missing xmlns
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 30 Mar 2012 00:17:13 +0200 |
parent | 250:a5ac643a7fd6 |
child | 312:f374daa3db4d |
rev | line source |
---|---|
250 | 1 local verse = require "verse"; |
2 local vcard = require "util.vcard"; | |
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 | 9 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza) |
10 local lCard, xCard; | |
11 xCard = stanza:get_child("vCard", xmlns_vcard); | |
12 if stanza.attr.type == "result" and xCard then | |
13 lCard = vcard.xep54_to_lua(xCard) | |
14 vCard = vcard.xep54_to_text(xCard) | |
15 -- FIXME This is only until util.vcard.lua_to_text() is implemented | |
16 lCard._text = vCard; | |
17 callback(lCard) | |
18 else | |
19 callback(false) -- FIXME add error | |
20 end | |
21 end or nil); | |
22 end | |
195
dc61684e8dbf
plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
228 | 24 function stream:set_vcard(aCard, callback) |
25 local xCard; | |
26 if type(aCard) == "table" and aCard.name then | |
27 xCard = aCard; | |
28 elseif type(aCard) == "string" then | |
29 xCard = vcard.text_to_xep54(aCard)[1]; | |
30 elseif type(aCard) == "table" then | |
31 error("Converting a table to vCard not implemented") | |
32 end | |
33 if not xCard then return false end | |
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 | 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 |