mod_profile/mod_profile.lua
changeset 3190 1fe5b156d220
parent 3189 973caebcb40b
child 3191 7c450c27d4ba
equal deleted inserted replaced
3189:973caebcb40b 3190: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