MUC: Fix delay@from to be room JID (fixes #1416)
[prosody.git] / plugins / mod_vcard4.lua
blob378c0602a88d50c188fa8bbda1b7191589a81a45
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();
8 end);
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);
15 if ok and item then
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"));
21 else
22 origin.send(st.error_reply(stanza, "modify", "undefined-condition"));
23 end
24 return true;
25 end);
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);
36 if ok then
37 origin.send(st.reply(stanza));
38 elseif err == "forbidden" then
39 origin.send(st.error_reply(stanza, "auth", "forbidden"));
40 else
41 origin.send(st.error_reply(stanza, "modify", "undefined-condition", err));
42 end
43 return true;
44 end);