Comparison

plugins/mod_vcard_legacy.lua @ 9810:2d8e2de36654 0.11

mod_vcard_legacy: Upgrade vcard-temp on login (fixes #1289)
author Kim Alvefur <zash@zash.se>
date Thu, 10 Jan 2019 15:39:02 +0100
parent 9809:5648e8733569
child 9811:ce6eb482eb50
comparison
equal deleted inserted replaced
9809:5648e8733569 9810:2d8e2de36654
126 elseif info and info.attr.url then 126 elseif info and info.attr.url then
127 vcard_temp:text_tag("EXTVAL", info.attr.url); 127 vcard_temp:text_tag("EXTVAL", info.attr.url);
128 end 128 end
129 vcard_temp:up(); 129 vcard_temp:up();
130 end 130 end
131 end
132
133 if not vcard_temp.tags[1] then
134 vcard_temp = st.deserialize(vcards:get(jid_split(stanza.attr.to) or origin.username)) or vcard_temp;
135 end 131 end
136 132
137 origin.send(st.reply(stanza):add_child(vcard_temp)); 133 origin.send(st.reply(stanza):add_child(vcard_temp));
138 return true; 134 return true;
139 end); 135 end);
308 end 304 end
309 305
310 module:hook("pre-presence/full", inject_xep153, 1); 306 module:hook("pre-presence/full", inject_xep153, 1);
311 module:hook("pre-presence/bare", inject_xep153, 1); 307 module:hook("pre-presence/bare", inject_xep153, 1);
312 module:hook("pre-presence/host", inject_xep153, 1); 308 module:hook("pre-presence/host", inject_xep153, 1);
309
310 module:hook("resource-bind", function (event)
311 local session = event.session;
312 local username = session.username;
313 local vcard_temp = vcards:get(username);
314 if not vcard_temp then
315 session.log("debug", "No legacy vCard to migrate or already migrated");
316 return;
317 end
318 vcard_temp = st.deserialize(vcard_temp);
319 local pep_service = mod_pep.get_pep_service(username);
320 local ok, err = save_to_pep(pep_service, true, vcard_to_pep(vcard_temp));
321 if ok and vcards:set(username, nil) then
322 session.log("info", "Migrated vCard-temp to PEP");
323 else
324 session.log("info", "Failed to migrate vCard-temp to PEP: %s", err or "problem emptying 'vcard' store");
325 end
326 end);