Software /
code /
prosody-modules
Changeset
3739:1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 13 Nov 2019 16:25:21 +0100 |
parents | 3738:9cd6d602ad1b |
children | 3740:b3fb32bd1f01 |
files | mod_bookmarks2/mod_bookmarks2.lua |
diffstat | 1 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_bookmarks2/mod_bookmarks2.lua Wed Nov 13 15:51:59 2019 +0100 +++ b/mod_bookmarks2/mod_bookmarks2.lua Wed Nov 13 16:25:21 2019 +0100 @@ -95,13 +95,17 @@ a_password == b_password); end -local function publish_to_pep(jid, bookmarks) +local function publish_to_pep(jid, bookmarks, synchronise) local service = mod_pep.get_pep_service(jid_split(jid)); - -- If we set zero legacy bookmarks, purge the bookmarks 2 node. if #bookmarks.tags == 0 then - module:log("debug", "No bookmark in the set, purging instead."); - return service:purge("urn:xmpp:bookmarks:0", jid, true); + if synchronise then + -- If we set zero legacy bookmarks, purge the bookmarks 2 node. + module:log("debug", "No bookmark in the set, purging instead."); + return service:purge("urn:xmpp:bookmarks:0", jid, true); + else + return true; + end end -- Retrieve the current bookmarks2. @@ -168,12 +172,14 @@ end -- Now handle retracting items that have been removed. - for id in pairs(to_remove) do - module:log("debug", "Item %s removed from bookmarks.", id); - local ok, err = service:retract("urn:xmpp:bookmarks:0", jid, id, st.stanza("retract", { id = id })); - if not ok then - module:log("error", "Retracting item %s failed: %s", id, err); - return ok, err; + if synchronise then + for id in pairs(to_remove) do + module:log("debug", "Item %s removed from bookmarks.", id); + local ok, err = service:retract("urn:xmpp:bookmarks:0", jid, id, st.stanza("retract", { id = id })); + if not ok then + module:log("error", "Retracting item %s failed: %s", id, err); + return ok, err; + end end end return true; @@ -194,7 +200,7 @@ module:log("debug", "Private bookmarks set by client, publishing to pep."); - local ok, err = publish_to_pep(session.full_jid, bookmarks); + local ok, err = publish_to_pep(session.full_jid, bookmarks, true); if not ok then module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); @@ -224,12 +230,8 @@ local bookmarks = st.deserialize(data); module:log("debug", "Got legacy bookmarks of %s: %s", jid, bookmarks); - -- We don’t care if deleting succeeds or not, we only want to start with a non-existent node. - module:log("debug", "Deleting possibly existing PEP item for %s.", jid); - service:delete("urn:xmpp:bookmarks:0", jid); - module:log("debug", "Going to store PEP item for %s.", jid); - local ok, err = publish_to_pep(session.full_jid, bookmarks); + local ok, err = publish_to_pep(session.full_jid, bookmarks, false); if not ok then module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err); return;