mod_bookmarks/mod_bookmarks.lua
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
Tue, 21 Aug 2018 17:18:31 +0100
changeset 3257 cf8ad9fd7f15
parent 3242 786ba175f2e5
child 3286 9346ed926842
permissions -rw-r--r--
mod_bookmarks: Use the new item-published/<node> event.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3242
786ba175f2e5 mod_bookmarks: Require forgotten util.jid module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3239
diff changeset
     1
local st = require "util.stanza";
786ba175f2e5 mod_bookmarks: Require forgotten util.jid module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3239
diff changeset
     2
local jid_split = require "util.jid".split;
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     3
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     4
local mod_pep = module:depends "pep";
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     5
local private_storage = module:open_store("private", "map");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     6
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     7
module:hook("account-disco-info", function (event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     8
	event.reply:tag("feature", { var = "urn:xmpp:bookmarks-conversion:0" }):up();
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
     9
end);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    10
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    11
local function on_retrieve_private_xml(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    12
	local stanza, session = event.stanza, event.origin;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    13
	local query = stanza:get_child("query", "jabber:iq:private");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    14
	if query == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    15
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    16
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    17
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    18
	local bookmarks = query:get_child("storage", "storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    19
	if bookmarks == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    20
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    21
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    22
3234
ba0d444b64aa mod_bookmarks: Simplify last item retrieval thanks to Prosody b6ffd4f951b9.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
    23
	module:log("debug", "Getting private bookmarks: %s", bookmarks);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    24
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    25
	local username = session.username;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    26
	local service = mod_pep.get_pep_service(username);
3234
ba0d444b64aa mod_bookmarks: Simplify last item retrieval thanks to Prosody b6ffd4f951b9.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
    27
	local ok, id, item = service:get_last_item("storage:bookmarks", session.full_jid);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    28
	if not ok then
3234
ba0d444b64aa mod_bookmarks: Simplify last item retrieval thanks to Prosody b6ffd4f951b9.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3233
diff changeset
    29
		module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", username, id);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    30
		session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP"));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    31
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    32
	end
3237
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    33
	if not id or not item then
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    34
		module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", username);
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    35
		session.send(st.reply(stanza):add_child(query));
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    36
		return
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    37
	end
176b537a658c mod_bookmarks: Send back empty Private XML bookmarks on empty PEP bookmarks.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3236
diff changeset
    38
	module:log("debug", "Got item %s: %s", id, item);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    39
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    40
	local content = item.tags[1];
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    41
	module:log("debug", "Sending back private for %s: %s", username, content);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    42
	session.send(st.reply(stanza):query("jabber:iq:private"):add_child(content));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    43
	return true;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    44
end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    45
3239
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3238
diff changeset
    46
function publish_to_pep(jid, bookmarks)
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3238
diff changeset
    47
	local service = mod_pep.get_pep_service(jid_split(jid));
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    48
	local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    49
		:add_child(bookmarks);
3235
f7777bc6e677 mod_bookmarks: Enforce publish_options since Prosody 249d90ff992e.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
    50
	local options = {
f7777bc6e677 mod_bookmarks: Enforce publish_options since Prosody 249d90ff992e.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
    51
		["persist_items"] = true;
f7777bc6e677 mod_bookmarks: Enforce publish_options since Prosody 249d90ff992e.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
    52
		["access_model"] = "whitelist";
f7777bc6e677 mod_bookmarks: Enforce publish_options since Prosody 249d90ff992e.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
    53
	};
f7777bc6e677 mod_bookmarks: Enforce publish_options since Prosody 249d90ff992e.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3234
diff changeset
    54
	return service:publish("storage:bookmarks", jid, "current", item, options);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    55
end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    56
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    57
-- Synchronise Private XML to PEP.
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    58
local function on_publish_private_xml(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    59
	local stanza, session = event.stanza, event.origin;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    60
	local query = stanza:get_child("query", "jabber:iq:private");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    61
	if query == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    62
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    63
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    64
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    65
	local bookmarks = query:get_child("storage", "storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    66
	if bookmarks == nil then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    67
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    68
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    69
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    70
	module:log("debug", "Private bookmarks set by client, publishing to pep");
3239
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3238
diff changeset
    71
	local ok, err = publish_to_pep(session.full_jid, bookmarks);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    72
	if not ok then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    73
		module:log("error", "Failed to publish to PEP bookmarks for %s: %s", session.username, err);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    74
		session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP"));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    75
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    76
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    77
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    78
	session.send(st.reply(stanza));
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    79
	return true;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    80
end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    81
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    82
local function on_resource_bind(event)
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    83
	local session = event.session;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    84
	local username = session.username;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    85
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    86
	local data, err = private_storage:get(username, "storage:storage:bookmarks");
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    87
	if not data then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    88
		module:log("debug", "No existing Private XML bookmarks for %s, migration already done: %s", username, err);
3238
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    89
		local service = mod_pep.get_pep_service(username);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    90
		local ok, id = service:get_last_item("storage:bookmarks", session.full_jid);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    91
		if not ok or not id then
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    92
			module:log("debug", "Additionally, no PEP bookmarks were existing for %s", username);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    93
			module:fire_event("bookmarks/empty", { session = session });
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
    94
		end
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    95
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    96
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    97
	local bookmarks = st.deserialize(data);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    98
	module:log("debug", "Got private bookmarks of %s: %s", username, bookmarks);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
    99
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   100
	module:log("debug", "Going to store PEP item for %s", username);
3239
bd8e94ff726b mod_bookmarks: Expose publish_to_pep() to other modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3238
diff changeset
   101
	local ok, err = publish_to_pep(session.full_jid, bookmarks);
3233
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   102
	if not ok then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   103
		module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", username, err);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   104
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   105
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   106
	module:log("debug", "Stored bookmarks to PEP for %s", username);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   107
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   108
	local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   109
	if not ok then
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   110
		module:log("error", "Failed to remove private bookmarks of %s: %s", username, err);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   111
		return;
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   112
	end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   113
	module:log("debug", "Removed private bookmarks of %s, migration done!", username);
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   114
end
e8963e328b26 mod_bookmarks: New module synchronising bookmarks to the new persistent mod_pep
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
   115
3238
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   116
local function on_item_published(event)
3257
cf8ad9fd7f15 mod_bookmarks: Use the new item-published/<node> event.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3242
diff changeset
   117
	module:fire_event("bookmarks/updated", event);
3238
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   118
end
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   119
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   120
module:hook("iq-get/bare/jabber:iq:private:query", on_retrieve_private_xml);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   121
module:hook("iq-set/bare/jabber:iq:private:query", on_publish_private_xml);
b1e25943a004 mod_bookmarks: Fire empty and updated events, for other modules to use.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3237
diff changeset
   122
module:hook("resource-bind", on_resource_bind);
3257
cf8ad9fd7f15 mod_bookmarks: Use the new item-published/<node> event.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 3242
diff changeset
   123
module:hook("item-published/storage:bookmarks", on_item_published);