aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-06-01 17:37:54 +0200
committerKim Alvefur <zash@zash.se>2020-06-01 17:37:54 +0200
commitcd40d2a63038338c66c0d7115dfb87ab4b1c6ca6 (patch)
tree0d669df29c8e8af5ed826189c1a32051beee2836
parent81457f2fff2c6700073c3df3af2565f250df3045 (diff)
downloadprosody-cd40d2a63038338c66c0d7115dfb87ab4b1c6ca6.tar.gz
prosody-cd40d2a63038338c66c0d7115dfb87ab4b1c6ca6.zip
mod_vcard_legacy: Remove semi-broken support for multiple avatars
Nobody does this. If someone wants to they should go use the PEP method directly instead. Additionally, this got in the way of doing multiple avatars The PEP Way, since it treated each 'data' as a distinct avatar with an optional corresponding 'metadata', which is not how it works.
-rw-r--r--plugins/mod_vcard_legacy.lua62
1 files changed, 28 insertions, 34 deletions
diff --git a/plugins/mod_vcard_legacy.lua b/plugins/mod_vcard_legacy.lua
index a6ff47d0..3b175df4 100644
--- a/plugins/mod_vcard_legacy.lua
+++ b/plugins/mod_vcard_legacy.lua
@@ -126,22 +126,25 @@ module:hook("iq-get/bare/vcard-temp:vCard", function (event)
end
end
- local meta_ok, avatar_meta = pep_service:get_items("urn:xmpp:avatar:metadata", stanza.attr.from);
- local data_ok, avatar_data = pep_service:get_items("urn:xmpp:avatar:data", stanza.attr.from);
-
- if data_ok then
- for _, hash in ipairs(avatar_data) do
- local meta = meta_ok and avatar_meta[hash];
- local data = avatar_data[hash];
- local info = meta and meta.tags[1]:get_child("info");
+ local ok, avatar_hash, meta = pep_service:get_last_item("urn:xmpp:avatar:metadata", true);
+ if ok and avatar_hash then
+
+ local info = meta.tags[1]:get_child("info");
+ if info then
vcard_temp:tag("PHOTO");
- if info and info.attr.type then
+
+ if info.attr.type then
vcard_temp:text_tag("TYPE", info.attr.type);
end
- if data then
- vcard_temp:text_tag("BINVAL", data.tags[1]:get_text());
- elseif info and info.attr.url then
+
+ if info.attr.url then
vcard_temp:text_tag("EXTVAL", info.attr.url);
+ elseif info.attr.id then
+ local data_ok, avatar_data = pep_service:get_items("urn:xmpp:avatar:data", stanza.attr.from, { info.attr.id });
+ if data_ok and avatar_data and avatar_data[info.attr.id] then
+ local data = avatar_data[info.attr.id];
+ vcard_temp:text_tag("BINVAL", data.tags[1]:get_text());
+ end
end
vcard_temp:up();
end
@@ -157,7 +160,7 @@ local node_defaults = {
};
function vcard_to_pep(vcard_temp)
- local avatars = {};
+ local avatar = {};
local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
:tag("vcard", { xmlns = 'urn:ietf:params:xml:ns:vcard-4.0' });
@@ -246,7 +249,9 @@ function vcard_to_pep(vcard_temp)
local avatar_raw = base64_decode(avatar_payload);
local avatar_hash = sha1(avatar_raw, true);
- local avatar_meta = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" })
+ avatar.hash = avatar_hash;
+
+ avatar.meta = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" })
:tag("metadata", { xmlns="urn:xmpp:avatar:metadata" })
:tag("info", {
bytes = tostring(#avatar_raw),
@@ -254,40 +259,29 @@ function vcard_to_pep(vcard_temp)
type = avatar_type,
});
- local avatar_data = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" })
+ avatar.data = st.stanza("item", { id = avatar_hash, xmlns = "http://jabber.org/protocol/pubsub" })
:tag("data", { xmlns="urn:xmpp:avatar:data" })
:text(avatar_payload);
- table.insert(avatars, { hash = avatar_hash, meta = avatar_meta, data = avatar_data });
end
end
end
- return vcard4, avatars;
+ return vcard4, avatar;
end
-function save_to_pep(pep_service, actor, vcard4, avatars)
- if avatars then
+function save_to_pep(pep_service, actor, vcard4, avatar)
+ if avatar then
if pep_service:purge("urn:xmpp:avatar:metadata", actor) then
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;
+ local ok, err = pep_service:publish("urn:xmpp:avatar:data", actor, avatar.hash, avatar.data, node_defaults);
+ if ok then
+ ok, err = pep_service:publish("urn:xmpp:avatar:metadata", actor, avatar.hash, avatar.meta, node_defaults);
end
- for _, avatar in ipairs(avatars) do
- 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, avatar_defaults);
- end
- if not ok then
- return ok, err;
- end
+ if not ok then
+ return ok, err;
end
end