Software /
code /
verse
Annotate
plugins/vcard.lua @ 312:f374daa3db4d
plugins.vcard: Update for never util.vcard
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 27 Aug 2012 00:13:47 +0200 |
parent | 250:a5ac643a7fd6 |
child | 313:d0d378f15d16 |
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; | |
312
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
11 vCard = stanza:get_child("vCard", xmlns_vcard); |
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
12 if stanza.attr.type == "result" and vCard then |
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
13 vCard = vcard.from_xep54(xCard) |
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
14 callback(vCard) |
228 | 15 else |
16 callback(false) -- FIXME add error | |
17 end | |
18 end or nil); | |
19 end | |
195
dc61684e8dbf
plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 |
228 | 21 function stream:set_vcard(aCard, callback) |
22 local xCard; | |
23 if type(aCard) == "table" and aCard.name then | |
24 xCard = aCard; | |
25 elseif type(aCard) == "string" then | |
312
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
26 xCard = vcard.from_text(aCard)[1]; |
228 | 27 elseif type(aCard) == "table" then |
312
f374daa3db4d
plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents:
250
diff
changeset
|
28 xCard = vcard.to_xep54(aCard); |
228 | 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)); | |
195
dc61684e8dbf
plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 stream:send_iq(verse.iq({type="set"}) |
228 | 34 :add_child(xCard), callback); |
195
dc61684e8dbf
plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end |
dc61684e8dbf
plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end |