Annotate

plugins/vcard.lua @ 449:c720f331327c

plugins.smacks: Restructure events to avoid double hooks after (failed) resumption
author Kim Alvefur <zash@zash.se>
date Sat, 19 Feb 2022 15:52:10 +0100
parent 395:e86144a4eaa1
child 490:6b2f31da9610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
1 local verse = require "verse";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
2 local vcard = require "util.vcard";
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 228
diff changeset
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
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
9 :tag("vCard", {xmlns=xmlns_vcard}), callback and function(stanza)
395
e86144a4eaa1 plugins: Cleanup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 316
diff changeset
10 local vCard = stanza:get_child("vCard", xmlns_vcard);
312
f374daa3db4d plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
11 if stanza.attr.type == "result" and vCard then
313
d0d378f15d16 plugins.vcard: Fix previous commit
Kim Alvefur <zash@zash.se>
parents: 312
diff changeset
12 vCard = vcard.from_xep54(vCard)
312
f374daa3db4d plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
13 callback(vCard)
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
14 else
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
15 callback(false) -- FIXME add error
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
16 end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
17 end or nil);
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
18 end
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
20 function stream:set_vcard(aCard, callback)
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
21 local xCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
22 if type(aCard) == "table" and aCard.name then
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
23 xCard = aCard;
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
24 elseif type(aCard) == "string" then
316
03ad51d96858 plugins.vcard: Convert textual vCards to XEP-54 format
Kim Alvefur <zash@zash.se>
parents: 313
diff changeset
25 xCard = vcard.to_xep54(vcard.from_text(aCard)[1]);
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
26 elseif type(aCard) == "table" then
312
f374daa3db4d plugins.vcard: Update for never util.vcard
Kim Alvefur <zash@zash.se>
parents: 250
diff changeset
27 xCard = vcard.to_xep54(aCard);
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
28 error("Converting a table to vCard not implemented")
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
29 end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
30 if not xCard then return false end
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
31 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
32 stream:send_iq(verse.iq({type="set"})
228
c5a4f82e2fd6 plugins.vcard: Use util.vcard
Kim Alvefur <zash@zash.se>
parents: 195
diff changeset
33 :add_child(xCard), callback);
195
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 end
dc61684e8dbf plugins.vcard: Get and set vcard-temp info.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end