Comparison

mod_bookmarks2/mod_bookmarks2.lua @ 3743:5eab799b5fa4

mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 13 Nov 2019 16:54:36 +0100
parent 3742:05bca7a771d6
child 4279:776eacd233b5
comparison
equal deleted inserted replaced
3742:05bca7a771d6 3743:5eab799b5fa4
274 local function on_node_created(event) 274 local function on_node_created(event)
275 local service, node, actor = event.service, event.node, event.actor; 275 local service, node, actor = event.service, event.node, event.actor;
276 if node ~= "storage:bookmarks" then 276 if node ~= "storage:bookmarks" then
277 return; 277 return;
278 end 278 end
279 local ok, node_config = service:get_node_config(node, actor); 279
280 if not ok then 280 module:log("debug", "Something tried to create legacy PEP bookmarks for %s.", actor);
281 module:log("error", "Failed to get node config of %s: %s", node, node_config); 281 local ok, err = service:delete("storage:bookmarks", actor);
282 return; 282 if not ok then
283 end 283 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", actor, err);
284 local changed = false; 284 end
285 for config_field, value in pairs(default_options) do 285 module:log("debug", "Legacy PEP bookmarks node of %s deleted.", actor);
286 if node_config[config_field] ~= value then
287 node_config[config_field] = value;
288 changed = true;
289 end
290 end
291 if not changed then
292 return;
293 end
294 local ok, err = service:set_node_config(node, actor, node_config);
295 if not ok then
296 module:log("error", "Failed to set node config of %s: %s", node, err);
297 return;
298 end
299 end 286 end
300 287
301 module:hook("iq/bare/jabber:iq:private:query", function (event) 288 module:hook("iq/bare/jabber:iq:private:query", function (event)
302 if event.stanza.attr.type == "get" then 289 if event.stanza.attr.type == "get" then
303 return on_retrieve_private_xml(event); 290 return on_retrieve_private_xml(event);