Comparison

mod_profile/mod_profile.lua @ 3186:1fe5b156d220

mod_profile: Add support for XEP-0398
author Kim Alvefur <zash@zash.se>
date Fri, 13 Jul 2018 01:13:37 +0200
parent 3185:973caebcb40b
child 3187:7c450c27d4ba
comparison
equal deleted inserted replaced
3185:973caebcb40b 3186:1fe5b156d220
17 pep_plus = module:depends"pep_plus"; 17 pep_plus = module:depends"pep_plus";
18 end 18 end
19 19
20 local storage = module:open_store(); 20 local storage = module:open_store();
21 local legacy_storage = module:open_store("vcard"); 21 local legacy_storage = module:open_store("vcard");
22
23 module:hook("account-disco-info", function (event)
24 event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up();
25 end);
22 26
23 local function get_item(vcard, name) -- luacheck: ignore 431 27 local function get_item(vcard, name) -- luacheck: ignore 431
24 local item; 28 local item;
25 for i=1, #vcard do 29 for i=1, #vcard do
26 item=vcard[i]; 30 item=vcard[i];
231 return true; 235 return true;
232 end); 236 end);
233 end 237 end
234 end 238 end
235 239
240 local function inject_xep153(event)
241 local origin, stanza = event.origin, event.stanza;
242 local username = origin.username;
243 local pep = pep_plus.get_pep_service(username);
244
245 stanza:remove_children("x", "vcard-temp:x:update");
246 local x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" });
247 local avatar_hash = pep:get_items("urn:xmpp:avatar:metadata");
248 if avatar_hash then
249 x_update:text_tag("photo", avatar_hash);
250 end
251 stanza:add_direct_child(x_update);
252 end
253
254 if pep_plus then
255 module:hook("pre-presence/full", inject_xep153)
256 module:hook("pre-presence/bare", inject_xep153)
257 module:hook("pre-presence/host", inject_xep153)
258 end