From 839498eb5d7f275c21e0f63939b79bf0ff1f5fc1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 6 Feb 2025 17:03:03 +0000 Subject: mod_vcard: Some support for handling vcards on components --- plugins/mod_vcard.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua index cb3bfdeb..4cb14f81 100644 --- a/plugins/mod_vcard.lua +++ b/plugins/mod_vcard.lua @@ -7,6 +7,7 @@ -- local base64 = require "prosody.util.encodings".base64; +local jid = require "prosody.util.jid"; local sha1 = require "prosody.util.hashes".sha1; local st = require "prosody.util.stanza" local jid_split = require "prosody.util.jid".split; @@ -15,6 +16,8 @@ local vcards = module:open_store(); module:add_feature("vcard-temp"); +local is_component = module:get_host_type() == "component"; + local function handle_vcard(event) local session, stanza = event.origin, event.stanza; local to = stanza.attr.to; @@ -23,7 +26,7 @@ local function handle_vcard(event) if to then local node = jid_split(to); vCard = st.deserialize(vcards:get(node)); -- load vCard for user or server - else + elseif not is_component then vCard = st.deserialize(vcards:get(session.username));-- load user's own vCard end if vCard then @@ -32,8 +35,9 @@ local function handle_vcard(event) session.send(st.error_reply(stanza, "cancel", "item-not-found")); end else -- stanza.attr.type == "set" - if not to then - if vcards:set(session.username, st.preserialize(stanza.tags[1])) then + if not to or (is_component and event.allow_vcard_modification) then + local node = is_component and jid.node(stanza.attr.to) or session.username; + if vcards:set(node, st.preserialize(stanza.tags[1])) then session.send(st.reply(stanza)); module:fire_event("vcard-updated", event); else -- cgit v1.2.3