Software /
code /
prosody
Annotate
plugins/mod_bookmarks.lua @ 12152:0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 06 Jan 2022 00:59:40 +0100 |
parent | 12149:bbbf0dd90b6d |
child | 12155:ae5988739990 |
rev | line source |
---|---|
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 local mm = require "core.modulemanager"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 if mm.get_modules_for_host(module.host):contains("bookmarks2") then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 error("mod_bookmarks and mod_bookmarks2 are conflicting, please disable one of them.", 0); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 local jid_split = require "util.jid".split; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 local mod_pep = module:depends "pep"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local private_storage = module:open_store("private", "map"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 local namespace = "urn:xmpp:bookmarks:1"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 local namespace_private = "jabber:iq:private"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 local namespace_legacy = "storage:bookmarks"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 local default_options = { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 ["persist_items"] = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 ["max_items"] = "max"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 ["send_last_published_item"] = "never"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 ["access_model"] = "whitelist"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 }; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 module:hook("account-disco-info", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 -- This Time it’s Serious! |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 event.reply:tag("feature", { var = namespace.."#compat" }):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 event.reply:tag("feature", { var = namespace.."#compat-pep" }):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 end); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 -- This must be declared on the domain JID, not the account JID. Note that |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 -- this isn’t defined in the XEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 module:add_feature(namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 local function generate_legacy_storage(items) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 local storage = st.stanza("storage", { xmlns = namespace_legacy }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 for _, item_id in ipairs(items) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 local item = items[item_id]; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 local bookmark = item:get_child("conference", namespace); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
38 local conference = st.stanza("conference", { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 jid = item.attr.id, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 name = bookmark.attr.name, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 autojoin = bookmark.attr.autojoin, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 local nick = bookmark:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 if nick ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 conference:text_tag("nick", nick):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 local password = bookmark:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 if password ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 conference:text_tag("password", password):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 storage:add_child(conference); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 return storage; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 local function on_retrieve_legacy_pep(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 if pubsub == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 local items = pubsub:get_child("items"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 if items == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 local node = items.attr.node; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 if node ~= namespace_legacy then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 local ok, ret = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 local storage = generate_legacy_storage(ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 module:log("debug", "Sending back legacy PEP for %s: %s", jid, storage); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 session.send(st.reply(stanza) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 :tag("pubsub", {xmlns = "http://jabber.org/protocol/pubsub"}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 :tag("items", {node = namespace_legacy}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 :tag("item", {id = "current"}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 :add_child(storage)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 local function on_retrieve_private_xml(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 local query = stanza:get_child("query", namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 if query == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 local bookmarks = query:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 module:log("debug", "Getting private bookmarks: %s", bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 local ok, ret = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 if ret == "item-not-found" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 session.send(st.reply(stanza):add_child(query)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 local storage = generate_legacy_storage(ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 module:log("debug", "Sending back private for %s: %s", jid, storage); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 session.send(st.reply(stanza):query(namespace_private):add_child(storage)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 local function compare_bookmark2(a, b) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 if a == nil or b == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 return false; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 local a_conference = a:get_child("conference", namespace); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 local b_conference = b:get_child("conference", namespace); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 local a_nick = a_conference:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 local b_nick = b_conference:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 local a_password = a_conference:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 local b_password = b_conference:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 return (a.attr.id == b.attr.id and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 a_conference.attr.name == b_conference.attr.name and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 a_conference.attr.autojoin == b_conference.attr.autojoin and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 a_nick == b_nick and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 a_password == b_password); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 local function publish_to_pep(jid, bookmarks, synchronise) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 local service = mod_pep.get_pep_service(jid_split(jid)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 if #bookmarks.tags == 0 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 if synchronise then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 -- If we set zero legacy bookmarks, purge the bookmarks 2 node. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 module:log("debug", "No bookmark in the set, purging instead."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 return service:purge(namespace, jid, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 -- Retrieve the current bookmarks2. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 module:log("debug", "Retrieving the current bookmarks 2."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 local has_bookmarks2, ret = service:get_items(namespace, jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 local bookmarks2; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 if not has_bookmarks2 and ret == "item-not-found" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 module:log("debug", "Got item-not-found, assuming it was empty until now, creating."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 local ok, err = service:create(namespace, jid, default_options); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 module:log("error", "Creating bookmarks 2 node failed: %s", err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 bookmarks2 = {}; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 elseif not has_bookmarks2 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 module:log("debug", "Got %s error, aborting.", ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 return false, ret; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 module:log("debug", "Got existing bookmarks2."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 bookmarks2 = ret; |
12152
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
179 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
180 local ok, err = service:get_node_config(namespace, jid); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
181 if not ok then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
182 module:log("error", "Retrieving bookmarks 2 node config failed: %s", err); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
183 return ok, err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
184 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
185 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
186 local options = err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
187 for key, value in pairs(default_options) do |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
188 if options[key] and options[key] ~= value then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
189 module:log("warn", "Overriding bookmarks 2 configuration for %s, from %s to %s", jid, options[key], value); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
190 options[key] = value; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
191 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
192 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
193 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
194 local ok, err = service:set_node_config(namespace, jid, options); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
195 if not ok then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
196 module:log("error", "Setting bookmarks 2 node config failed: %s", err); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
197 return ok, err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
198 end |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 -- Get a list of all items we may want to remove. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 local to_remove = {}; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 for i in ipairs(bookmarks2) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 to_remove[bookmarks2[i]] = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 for bookmark in bookmarks:childtags("conference", namespace_legacy) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 -- Create the new conference element by copying everything from the legacy one. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 local conference = st.stanza("conference", { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 xmlns = namespace, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 name = bookmark.attr.name, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 autojoin = bookmark.attr.autojoin, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 local nick = bookmark:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 if nick ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 conference:text_tag("nick", nick):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 local password = bookmark:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 if password ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 conference:text_tag("password", password):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 -- Create its wrapper. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = bookmark.attr.jid }) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 :add_child(conference); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 -- Then publish it only if it’s a new one or updating a previous one. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 if compare_bookmark2(item, bookmarks2[bookmark.attr.jid]) then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 module:log("debug", "Item %s identical to the previous one, skipping.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 to_remove[bookmark.attr.jid] = nil; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 if bookmarks2[bookmark.attr.jid] == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 module:log("debug", "Item %s not existing previously, publishing.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 module:log("debug", "Item %s different from the previous one, publishing.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 to_remove[bookmark.attr.jid] = nil; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 local ok, err = service:publish(namespace, jid, bookmark.attr.jid, item, default_options); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 module:log("error", "Publishing item %s failed: %s", item.attr.id, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 -- Now handle retracting items that have been removed. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 if synchronise then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 for id in pairs(to_remove) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 module:log("debug", "Item %s removed from bookmarks.", id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 local ok, err = service:retract(namespace, jid, id, st.stanza("retract", { id = id })); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 module:log("error", "Retracting item %s failed: %s", id, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 -- Synchronise legacy PEP to PEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 local function on_publish_legacy_pep(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 if pubsub == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
265 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 local publish = pubsub:get_child("publish"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 if publish == nil or publish.attr.node ~= namespace_legacy then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
273 local item = publish:get_child("item"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 if item == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
276 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
277 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
278 -- Here we ignore the item id, it’ll be generated as 'current' anyway. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
279 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
280 local bookmarks = item:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
281 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
283 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
284 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 -- We also ignore the publish-options. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
286 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
287 module:log("debug", "Legacy PEP bookmarks set by client, publishing to PEP."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
288 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
289 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
290 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
292 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
295 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
296 session.send(st.reply(stanza)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
297 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
300 -- Synchronise Private XML to PEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
301 local function on_publish_private_xml(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 local query = stanza:get_child("query", namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 if query == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 local bookmarks = query:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
311 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
313 module:log("debug", "Private bookmarks set by client, publishing to PEP."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
314 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
315 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
316 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
317 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
319 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
320 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
321 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
322 session.send(st.reply(stanza)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
325 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
326 local function migrate_legacy_bookmarks(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
327 local session = event.session; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
330 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
331 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
332 local ok, ret = service:get_items(namespace_legacy, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
333 if ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
334 module:log("debug", "Legacy PEP bookmarks found for %s, migrating.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
335 local failed = false; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
336 for _, item_id in ipairs(ret) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
337 local item = ret[item_id]; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
338 if item.attr.id ~= "current" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
339 module:log("warn", "Legacy PEP bookmarks for %s isn’t using 'current' as its id: %s", jid, item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
340 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
341 local bookmarks = item:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
342 module:log("debug", "Got legacy PEP bookmarks of %s: %s", jid, bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
343 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
345 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
346 module:log("error", "Failed to store legacy PEP bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
347 failed = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
348 break; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
349 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
350 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
351 if not failed then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
352 module:log("debug", "Successfully migrated legacy PEP bookmarks of %s to bookmarks 2, attempting deletion of the node.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
353 local ok, err = service:delete(namespace_legacy, jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
354 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
355 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
356 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
357 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
358 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
359 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
360 local data, err = private_storage:get(username, "storage:storage:bookmarks"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
361 if not data then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
362 module:log("debug", "No existing legacy bookmarks for %s, migration already done: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 local ok, ret2 = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
364 if not ok or not ret2 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
365 module:log("debug", "Additionally, no bookmarks 2 were existing for %s, assuming empty.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
366 module:fire_event("bookmarks/empty", { session = session }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
367 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
368 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
369 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 local bookmarks = st.deserialize(data); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 module:log("debug", "Got legacy bookmarks of %s: %s", jid, bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
373 module:log("debug", "Going to store legacy bookmarks to bookmarks 2 %s.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
375 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
376 module:log("error", "Failed to store legacy bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
377 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
378 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
379 module:log("debug", "Stored legacy bookmarks to bookmarks 2 for %s.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
380 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
381 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
382 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
383 module:log("error", "Failed to remove legacy bookmarks of %s: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
384 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
385 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
386 module:log("debug", "Removed legacy bookmarks of %s, migration done!", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
387 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
388 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
389 local function on_node_created(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
390 local service, node, actor = event.service, event.node, event.actor; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
391 if node ~= namespace_legacy then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
392 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
393 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
394 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
395 module:log("debug", "Something tried to create legacy PEP bookmarks for %s.", actor); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
396 local ok, err = service:delete(namespace_legacy, actor); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
397 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
398 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", actor, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
399 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
400 module:log("debug", "Legacy PEP bookmarks node of %s deleted.", actor); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
401 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
402 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
403 module:hook("iq/bare/jabber:iq:private:query", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
404 if event.stanza.attr.type == "get" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
405 return on_retrieve_private_xml(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
406 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
407 return on_publish_private_xml(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
408 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
409 end, 1); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
410 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
411 if event.stanza.attr.type == "get" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
412 return on_retrieve_legacy_pep(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
413 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
414 return on_publish_legacy_pep(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
415 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
416 end, 1); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
417 module:hook("resource-bind", migrate_legacy_bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
418 module:handle_items("pep-service", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
419 local service = event.item.service; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
420 module:hook_object_event(service.events, "node-created", on_node_created); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
421 end, function () end, true); |