# HG changeset patch
# User Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
# Date 1534599838 -3600
# Node ID 176b537a658c918d3d43b3167bea1d5b6d219476
# Parent  34e30a891bd3f85f56b6b27a6df9f4abc5b69df3
mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.

diff -r 34e30a891bd3 -r 176b537a658c mod_bookmarks/mod_bookmarks.lua
--- a/mod_bookmarks/mod_bookmarks.lua	Sat Aug 18 14:11:26 2018 +0100
+++ b/mod_bookmarks/mod_bookmarks.lua	Sat Aug 18 14:43:58 2018 +0100
@@ -23,13 +23,18 @@
 
 	local username = session.username;
 	local service = mod_pep.get_pep_service(username);
-	module:log("debug", "%s", session.full_jid);
 	local ok, id, item = service:get_last_item("storage:bookmarks", session.full_jid);
 	if not ok then
 		module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", username, id);
 		session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP"));
 		return;
 	end
+	if not id or not item then
+		module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", username);
+		session.send(st.reply(stanza):add_child(query));
+		return
+	end
+	module:log("debug", "Got item %s: %s", id, item);
 
 	local content = item.tags[1];
 	module:log("debug", "Sending back private for %s: %s", username, content);