Changeset

10269:4701415f5b0e 0.11

mod_vcard_legacy: Don't owerwrite empty photo elements (fixes #1432)
author Kim Alvefur <zash@zash.se>
date Sat, 21 Sep 2019 16:29:16 +0200
parents 10268:210278d5f995
children 10270:c2b9ff42db03 10293:f9301d93de72
files plugins/mod_vcard_legacy.lua
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_vcard_legacy.lua	Sat Sep 21 15:20:50 2019 +0200
+++ b/plugins/mod_vcard_legacy.lua	Sat Sep 21 16:29:16 2019 +0200
@@ -300,13 +300,19 @@
 	if stanza.attr.type then return end
 	local pep_service = mod_pep.get_pep_service(username);
 
-	stanza:remove_children("x", "vcard-temp:x:update");
-	local x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" }):tag("photo");
+	local x_update = stanza:get_child("x", "vcard-temp:x:update");
+	if not x_update then
+		x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" }):tag("photo");
+		stanza:add_direct_child(x_update);
+	elseif x_update:get_child("photo") then
+		return; -- XEP implies that these should be left alone
+	else
+		x_update:tag("photo");
+	end
 	local ok, avatar_hash = pep_service:get_last_item("urn:xmpp:avatar:metadata", true);
 	if ok and avatar_hash then
 		x_update:text(avatar_hash);
 	end
-	stanza:add_direct_child(x_update);
 end
 
 module:hook("pre-presence/full", inject_xep153, 1);