Diff

plugins/mod_vcard_legacy.lua @ 9809:5648e8733569 0.11

mod_vcard_legacy: Adapt node defaults to number of avatars
author Kim Alvefur <zash@zash.se>
date Fri, 11 Jan 2019 09:20:48 +0100
parent 9808:00d210deea28
child 9810:2d8e2de36654
line wrap: on
line diff
--- a/plugins/mod_vcard_legacy.lua	Fri Jan 11 09:20:45 2019 +0100
+++ b/plugins/mod_vcard_legacy.lua	Fri Jan 11 09:20:48 2019 +0100
@@ -254,10 +254,18 @@
 		pep_service:purge("urn:xmpp:avatar:data", actor);
 	end
 
+	local avatar_defaults = node_defaults;
+	if #avatars > 1 then
+		avatar_defaults = {};
+		for k,v in pairs(node_defaults) do
+			avatar_defaults[k] = v;
+		end
+		avatar_defaults.max_items = #avatars;
+	end
 	for _, avatar in ipairs(avatars) do
-		local ok, err = pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, node_defaults)
+		local ok, err = pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, avatar_defaults)
 		if ok then
-			ok, err = pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, node_defaults);
+			ok, err = pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, avatar_defaults);
 		end
 		if not ok then
 			return ok, err;