Changeset

3186:1fe5b156d220

mod_profile: Add support for XEP-0398
author Kim Alvefur <zash@zash.se>
date Fri, 13 Jul 2018 01:13:37 +0200
parents 3185:973caebcb40b
children 3187:7c450c27d4ba
files mod_profile/README.markdown mod_profile/mod_profile.lua
diffstat 2 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mod_profile/README.markdown	Fri Jul 13 01:13:06 2018 +0200
+++ b/mod_profile/README.markdown	Fri Jul 13 01:13:37 2018 +0200
@@ -11,6 +11,8 @@
 vCard 4 based protocol][xep0292] and integrates with [Personal
 Eventing Protocol][xep0163].
 
+Also supports [XEP-0398: User Avatar to vCard-Based Avatars Conversion].
+
 The vCard 4, [User Avatar][xep0084] and [User Nickname][xep0172]
 PEP nodes are updated when the vCard is changed..
 
--- a/mod_profile/mod_profile.lua	Fri Jul 13 01:13:06 2018 +0200
+++ b/mod_profile/mod_profile.lua	Fri Jul 13 01:13:37 2018 +0200
@@ -20,6 +20,10 @@
 local storage = module:open_store();
 local legacy_storage = module:open_store("vcard");
 
+module:hook("account-disco-info", function (event)
+	event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up();
+end);
+
 local function get_item(vcard, name) -- luacheck: ignore 431
 	local item;
 	for i=1, #vcard do
@@ -233,3 +237,22 @@
 	end
 end
 
+local function inject_xep153(event)
+	local origin, stanza = event.origin, event.stanza;
+	local username = origin.username;
+	local pep = pep_plus.get_pep_service(username);
+
+	stanza:remove_children("x", "vcard-temp:x:update");
+	local x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" });
+	local avatar_hash = pep:get_items("urn:xmpp:avatar:metadata");
+	if avatar_hash then
+		x_update:text_tag("photo", avatar_hash);
+	end
+	stanza:add_direct_child(x_update);
+end
+
+if pep_plus then
+	module:hook("pre-presence/full", inject_xep153)
+	module:hook("pre-presence/bare", inject_xep153)
+	module:hook("pre-presence/host", inject_xep153)
+end