Software /
code /
prosody
Changeset
9814:5eb4ef537e98 0.11
mod_vcard_legacy: Handle partial migration
Eg in case the user already published an avatar, migrate only the vcard,
and vice versa.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 26 Jan 2019 13:32:26 +0100 |
parents | 9813:071aaaa5cb34 |
children | 9815:fed614598f88 9816:7f84d7f77a00 |
files | plugins/mod_vcard_legacy.lua |
diffstat | 1 files changed, 34 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_vcard_legacy.lua Fri Jan 25 23:31:02 2019 +0100 +++ b/plugins/mod_vcard_legacy.lua Sat Jan 26 13:32:26 2019 +0100 @@ -245,30 +245,36 @@ end function save_to_pep(pep_service, actor, vcard4, avatars) + if avatars then - if pep_service:purge("urn:xmpp:avatar:metadata", actor) then - pep_service:purge("urn:xmpp:avatar:data", actor); - end + 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; + 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 - 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, 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; + 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 end end - return pep_service:publish("urn:xmpp:vcard4", actor, "current", vcard4, node_defaults); + if vcard4 then + return pep_service:publish("urn:xmpp:vcard4", actor, "current", vcard4, node_defaults); + end + + return true; end module:hook("iq-set/self/vcard-temp:vCard", function (event) @@ -317,15 +323,21 @@ return; end local pep_service = mod_pep.get_pep_service(username); - if pep_service:get_last_item("urn:xmpp:vcard4", true) - or pep_service:get_last_item("urn:xmpp:avatar:metadata", true) + vcard_temp = st.deserialize(vcard_temp); + local vcard4, avatars = vcard_to_pep(vcard_temp); + if pep_service:get_last_item("urn:xmpp:vcard4", true) then + vcard4 = nil; + end + if pep_service:get_last_item("urn:xmpp:avatar:metadata", true) or pep_service:get_last_item("urn:xmpp:avatar:data", true) then + avatars = nil; + end + if not (vcard4 or avatars) then session.log("debug", "Already PEP data, not overwriting with migrated data"); vcards:set(username, nil); return; end - vcard_temp = st.deserialize(vcard_temp); - local ok, err = save_to_pep(pep_service, true, vcard_to_pep(vcard_temp)); + local ok, err = save_to_pep(pep_service, true, vcard4, avatars); if ok and vcards:set(username, nil) then session.log("info", "Migrated vCard-temp to PEP"); else