Changeset

13656:4298e6565fec

mod_vcard: Some support for handling vcards on components
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Feb 2025 17:03:03 +0000
parents 13655:6902bb3dd196
children 13657:404d3644ac4a
files plugins/mod_vcard.lua
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_vcard.lua	Thu Feb 06 17:02:29 2025 +0000
+++ b/plugins/mod_vcard.lua	Thu Feb 06 17:03:03 2025 +0000
@@ -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 @@
 
 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 @@
 		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 @@
 			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