1 local st
= require
"util.stanza"
2 local jid_split
= require
"util.jid".split
;
4 local mod_pep
= module
:depends("pep");
6 module
:hook("account-disco-info", function (event
)
7 event
.reply
:tag("feature", { var
= "urn:ietf:params:xml:ns:vcard-4.0" }):up();
10 module
:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event
)
11 local origin
, stanza
= event
.origin
, event
.stanza
;
13 local pep_service
= mod_pep
.get_pep_service(jid_split(stanza
.attr
.to
) or origin
.username
);
14 local ok
, id
, item
= pep_service
:get_last_item("urn:xmpp:vcard4", stanza
.attr
.from
);
16 origin
.send(st
.reply(stanza
):add_child(item
.tags
[1]));
17 elseif item
== "item-not-found" or not id
then
18 origin
.send(st
.error_reply(stanza
, "cancel", "item-not-found"));
19 elseif item
== "forbidden" then
20 origin
.send(st
.error_reply(stanza
, "auth", "forbidden"));
22 origin
.send(st
.error_reply(stanza
, "modify", "undefined-condition"));
27 module
:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event
)
28 local origin
, stanza
= event
.origin
, event
.stanza
;
30 local vcard4
= st
.stanza("item", { xmlns
= "http://jabber.org/protocol/pubsub", id
= "current" })
31 :add_child(stanza
.tags
[1]);
33 local pep_service
= mod_pep
.get_pep_service(origin
.username
);
35 local ok
, err
= pep_service
:publish("urn:xmpp:vcard4", origin
.full_jid
, "current", vcard4
);
37 origin
.send(st
.reply(stanza
));
38 elseif err
== "forbidden" then
39 origin
.send(st
.error_reply(stanza
, "auth", "forbidden"));
41 origin
.send(st
.error_reply(stanza
, "modify", "undefined-condition", err
));