# HG changeset patch # User Kim Alvefur # Date 1531437217 -7200 # Node ID 1fe5b156d220bcd6a5d707a5674490509f6879db # Parent 973caebcb40b93dca78038ff3b17bf4425233cef mod_profile: Add support for XEP-0398 diff -r 973caebcb40b -r 1fe5b156d220 mod_profile/README.markdown --- 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.. diff -r 973caebcb40b -r 1fe5b156d220 mod_profile/mod_profile.lua --- 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