annotate mod_bookmarks2/mod_bookmarks2.lua @ 3677:90f88a643973

mod_bookmarks2: Add new module. This is the result of hacking during the Stockholm XMPP Sprint, for compatibility with older clients only doing Private XML XEP-0048. This module shouldn’t be loaded at the same time as mod_bookmarks, as both implement Private XML to achieve their conversion.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 28 Sep 2019 14:27:13 +0200
parents
children 7575399ae544
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3677
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 local st = require "util.stanza";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 local mod_pep = module:depends "pep";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 local private_storage = module:open_store("private", "map");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 local legacy_ns = "storage:bookmarks";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 local ns = "urn:xmpp:bookmarks:0";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 local default_options = {
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ["persist_items"] = true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ["max_items"] = 255;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ["send_last_published_item"] = "never";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 ["access_model"] = "whitelist";
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 };
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 module:hook("account-disco-info", function (event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 -- This Time it’s Serious!
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 event.reply:tag("feature", { var = "urn:xmpp:bookmarks:0#compat" }):up();
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 end);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 local function on_retrieve_private_xml(event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 local stanza, session = event.stanza, event.origin;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 local query = stanza:get_child("query", "jabber:iq:private");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 if query == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 local bookmarks = query:get_child("storage", "storage:bookmarks");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 if bookmarks == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 module:log("debug", "Getting private bookmarks: %s", bookmarks);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 local username = session.username;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 local jid = username.."@"..session.host;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 local service = mod_pep.get_pep_service(username);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 local ok, ret = service:get_items("urn:xmpp:bookmarks:0", session.full_jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 if ret == "item-not-found" then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 session.send(st.reply(stanza):add_child(query));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 else
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, id);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to retrive bookmarks from PEP"));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 return true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 local storage = st.stanza("storage", { xmlns = "storage:bookmarks" });
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 for i in ipairs(ret) do
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 local item = ret[ret[i]];
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 local conference = st.stanza("conference");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 conference.attr.jid = item.attr.id;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 local bookmark = item:get_child("conference", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 conference.attr.name = bookmark.attr.name;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 conference.attr.autojoin = bookmark.attr.autojoin;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 local nick = bookmark:get_child_text("nick", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 if nick ~= nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 conference:text_tag("nick", nick, { xmlns = "storage:bookmarks" }):up();
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 local password = bookmark:get_child_text("password", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 if password ~= nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 conference:text_tag("password", password):up();
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 storage:add_child(conference);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 module:log("debug", "Sending back private for %s: %s", jid, storage);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 session.send(st.reply(stanza):query("jabber:iq:private"):add_child(storage));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 return true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 local function compare_bookmark2(a, b)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 if a == nil or b == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 return false;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 local a_conference = a:get_child("conference", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 local b_conference = b:get_child("conference", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 local a_nick = a:get_child_text("nick", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 local b_nick = b:get_child_text("nick", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 local a_password = a:get_child_text("password", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 local b_password = b:get_child_text("password", "urn:xmpp:bookmarks:0");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 return (a.attr.id == b.attr.id and
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 a_conference.attr.name == b_conference.attr.name and
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 a_conference.attr.autojoin == b_conference.attr.autojoin and
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 a_nick == b_nick and
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 a_password == b_password);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 local function publish_to_pep(jid, bookmarks)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 local service = mod_pep.get_pep_service(jid_split(jid));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 -- If we set zero legacy bookmarks, purge the bookmarks 2 node.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 if #bookmarks.tags == 0 then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 module:log("debug", "No bookmark in the set, purging instead.");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 return service:purge("urn:xmpp:bookmarks:0", jid, true);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 -- Retrieve the current bookmarks2.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 module:log("debug", "Retrieving the current bookmarks 2.");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 local has_bookmarks2, ret = service:get_items("urn:xmpp:bookmarks:0", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 local bookmarks2;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 if not has_bookmarks2 and ret == "item-not-found" then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 module:log("debug", "Got item-not-found, assuming it was empty until now, creating.");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 local ok, err = service:create("urn:xmpp:bookmarks:0", jid, default_options);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 module:log("error", "Creating bookmarks 2 node failed: %s", err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 return ok, err;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 bookmarks2 = {};
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 elseif not has_bookmarks2 then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 module:log("debug", "Got %s error, aborting.", ret);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 return false, ret;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 else
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 module:log("debug", "Got existing bookmarks2.");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 bookmarks2 = ret;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 -- Get a list of all items we may want to remove.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 local to_remove = {};
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 for i in ipairs(bookmarks2) do
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 to_remove[bookmarks2[i]] = true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 for bookmark in bookmarks:childtags("conference", "storage:bookmarks") do
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 -- Create the new conference element by copying everything from the legacy one.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 local conference = st.stanza("conference", { xmlns = "urn:xmpp:bookmarks:0" });
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 conference.attr.name = bookmark.attr.name;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 conference.attr.autojoin = bookmark.attr.autojoin;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 local nick = bookmark:get_child_text("nick", "storage:bookmarks");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 if nick ~= nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 conference:text_tag("nick", nick, { xmlns = "urn:xmpp:bookmarks:0" }):up();
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 local password = bookmark:get_child_text("password", "storage:bookmarks");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 if password ~= nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 conference:text_tag("password", password, { xmlns = "urn:xmpp:bookmarks:0" }):up();
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 -- Create its wrapper.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = bookmark.attr.jid })
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 :add_child(conference);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 -- Then publish it only if it’s a new one or updating a previous one.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 if compare_bookmark2(item, bookmarks2[bookmark.attr.jid]) then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 module:log("debug", "Item %s identical to the previous one, skipping.", item.attr.id);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 to_remove[bookmark.attr.jid] = nil;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 else
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 if bookmarks2[bookmark.attr.jid] == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 module:log("debug", "Item %s not existing previously, publishing.", item.attr.id);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 else
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 module:log("debug", "Item %s different from the previous one, publishing.", item.attr.id);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 to_remove[bookmark.attr.jid] = nil;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 local ok, err = service:publish("urn:xmpp:bookmarks:0", jid, bookmark.attr.jid, item, default_options);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 module:log("error", "Publishing item %s failed: %s", item.attr.id, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 return ok, err;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 -- Now handle retracting items that have been removed.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 for id in pairs(to_remove) do
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 module:log("debug", "Item %s removed from bookmarks.", id);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 local ok, err = service:retract("urn:xmpp:bookmarks:0", jid, id, st.stanza("retract", { id = id }));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 module:log("error", "Retracting item %s failed: %s", id, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 return ok, err;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 return true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 -- Synchronise Private XML to PEP.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 local function on_publish_private_xml(event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 local stanza, session = event.stanza, event.origin;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 local query = stanza:get_child("query", "jabber:iq:private");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 if query == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 local bookmarks = query:get_child("storage", legacy_ns);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 if bookmarks == nil then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 module:log("debug", "Private bookmarks set by client, publishing to pep.");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 local ok, err = publish_to_pep(session.full_jid, bookmarks);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP"));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 return true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 session.send(st.reply(stanza));
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199 return true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 local function migrate_legacy_bookmarks(event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203 local session = event.session;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 local username = session.username;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 local service = mod_pep.get_pep_service(username);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 local jid = username.."@"..session.host;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 local data, err = private_storage:get(username, "storage:storage:bookmarks");
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 if not data then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 module:log("debug", "No existing legacy bookmarks for %s, migration already done: %s", jid, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 local ok, ret = service:get_items("urn:xmpp:bookmarks:0", session.full_jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212 if not ok or #ret.tags == 0 then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 module:log("debug", "Additionally, no bookmarks 2 were existing for %s, assuming empty.", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 module:fire_event("bookmarks/empty", { session = session });
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218 local bookmarks = st.deserialize(data);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 module:log("debug", "Got legacy bookmarks of %s: %s", jid, bookmarks);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221 -- We don’t care if deleting succeeds or not, we only want to start with a non-existent node.
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 module:log("debug", "Deleting possibly existing PEP item for %s.", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 service:delete("urn:xmpp:bookmarks:0", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 module:log("debug", "Going to store PEP item for %s.", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 local ok, err = publish_to_pep(session.full_jid, bookmarks);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 module:log("error", "Failed to store bookmarks to PEP for %s, aborting migration: %s", jid, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 module:log("debug", "Stored bookmarks to PEP for %s.", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 module:log("error", "Failed to remove private bookmarks of %s: %s", jid, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 module:log("debug", "Removed private bookmarks of %s, migration done!", jid);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 local function on_node_created(event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 local service, node, actor = event.service, event.node, event.actor;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 if node ~= "storage:bookmarks" then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 local ok, node_config = service:get_node_config(node, actor);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248 module:log("error", "Failed to get node config of %s: %s", node, node_config);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 local changed = false;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 for config_field, value in pairs(default_options) do
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 if node_config[config_field] ~= value then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 node_config[config_field] = value;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 changed = true;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258 if not changed then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 local ok, err = service:set_node_config(node, actor, node_config);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 if not ok then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 module:log("error", "Failed to set node config of %s: %s", node, err);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 return;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 module:hook("iq/bare/jabber:iq:private:query", function (event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 if event.stanza.attr.type == "get" then
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 return on_retrieve_private_xml(event);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 else
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272 return on_publish_private_xml(event);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 end
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 end, 1);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 module:hook("resource-bind", migrate_legacy_bookmarks);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 module:handle_items("pep-service", function (event)
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 local service = event.item.service;
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 module:hook_object_event(service.events, "node-created", on_node_created);
90f88a643973 mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 end, function () end, true);