Mercurial > prosody-modules
annotate mod_bookmarks2/mod_bookmarks2.lua @ 4834:7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
This implements the publish and items PubSub queries of XEP-0048 version 1.1,
ignoring item id, publish-options, and any other query.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 23 Dec 2021 17:44:35 +0100 |
parents | fdd9e5d89d73 |
children | 60b2dbe032c0 |
rev | line source |
---|---|
3678
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
1 local mm = require "core.modulemanager"; |
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
2 if mm.get_modules_for_host(module.host):contains("bookmarks") then |
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
3 error("mod_bookmarks2 and mod_bookmarks are conflicting, please disable one of them.", 0); |
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
4 end |
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
5 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 local jid_split = require "util.jid".split; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 local mod_pep = module:depends "pep"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local private_storage = module:open_store("private", "map"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 |
4640
d835cb7d2b47
mod_bookmarks2: Update namespace to :1
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4639
diff
changeset
|
12 local namespace = "urn:xmpp:bookmarks:1"; |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
13 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 local default_options = { |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 ["persist_items"] = true; |
3678
7575399ae544
mod_bookmarks, mod_bookmarks2: Refuse to load if the other one is also loaded.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3677
diff
changeset
|
16 -- This should be much higher, the XEP recommends 10000 but mod_pep rejects that. |
4719
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
17 ["max_items"] = "max"; |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 ["send_last_published_item"] = "never"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 ["access_model"] = "whitelist"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 }; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
4719
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
22 if not pcall(mod_pep.check_node_config, nil, nil, default_options) then |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
23 -- 0.11 or earlier not supporting max_items="max" trows an error here |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
24 module:log("debug", "Setting max_items=pep_max_items because 'max' is not supported in this version"); |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
25 default_options["max_items"] = module:get_option_number("pep_max_items", 256); |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
26 end |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
27 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 module:hook("account-disco-info", function (event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 -- This Time it’s Serious! |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
30 event.reply:tag("feature", { var = namespace.."#compat" }):up(); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 end); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
33 local function generate_legacy_storage(items) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
34 local storage = st.stanza("storage", { xmlns = "storage:bookmarks" }); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
35 for _, item_id in ipairs(items) do |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
36 local item = items[item_id]; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
37 local conference = st.stanza("conference"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
38 conference.attr.jid = item.attr.id; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
39 local bookmark = item:get_child("conference", namespace); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
40 conference.attr.name = bookmark.attr.name; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
41 conference.attr.autojoin = bookmark.attr.autojoin; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
42 local nick = bookmark:get_child_text("nick"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
43 if nick ~= nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
44 conference:text_tag("nick", nick, { xmlns = "storage:bookmarks" }):up(); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
45 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
46 local password = bookmark:get_child_text("password"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
47 if password ~= nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
48 conference:text_tag("password", password):up(); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
49 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
50 storage:add_child(conference); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
51 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
52 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
53 return storage; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
54 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
55 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
56 local function on_retrieve_legacy_pep(event) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
57 local stanza, session = event.stanza, event.origin; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
58 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
59 if pubsub == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
60 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
61 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
62 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
63 local items = pubsub:get_child("items"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
64 if items == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
65 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
66 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
67 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
68 local node = items.attr.node; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
69 if node ~= "storage:bookmarks" then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
70 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
71 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
72 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
73 local username = session.username; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
74 local jid = username.."@"..session.host; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
75 local service = mod_pep.get_pep_service(username); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
76 local ok, ret = service:get_items(namespace, session.full_jid); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
77 if not ok then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
78 if ret == "item-not-found" then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
79 module:log("debug", "Got no PEP bookmarks item for %s, returning empty legacy PEP bookmarks", jid); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
80 session.send(st.reply(stanza):add_child(query)); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
81 else |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
82 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
83 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
84 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
85 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
86 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
87 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
88 local storage = generate_legacy_storage(ret); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
89 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
90 module:log("debug", "Sending back legacy PEP for %s: %s", jid, storage); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
91 session.send(st.reply(stanza) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
92 :tag("pubsub", {xmlns = "http://jabber.org/protocol/pubsub"}) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
93 :tag("items", {node = "storage:bookmarks"}) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
94 :tag("item", {id = "current"}) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
95 :add_child(storage)); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
96 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
97 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
98 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 local function on_retrieve_private_xml(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 local stanza, session = event.stanza, event.origin; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 local query = stanza:get_child("query", "jabber:iq:private"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 if query == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 local bookmarks = query:get_child("storage", "storage:bookmarks"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 if bookmarks == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 module:log("debug", "Getting private bookmarks: %s", bookmarks); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 local username = session.username; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 local jid = username.."@"..session.host; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 local service = mod_pep.get_pep_service(username); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
116 local ok, ret = service:get_items(namespace, session.full_jid); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 if ret == "item-not-found" then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 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
|
120 session.send(st.reply(stanza):add_child(query)); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 else |
3740
b3fb32bd1f01
mod_bookmarks2: Use the correct error when failing to retrieve bookmarks2 to reply to Private XML request.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3739
diff
changeset
|
122 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
b3fb32bd1f01
mod_bookmarks2: Use the correct error when failing to retrieve bookmarks2 to reply to Private XML request.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3739
diff
changeset
|
123 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
128 local storage = generate_legacy_storage(ret); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 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
|
131 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
|
132 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 local function compare_bookmark2(a, b) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 if a == nil or b == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 return false; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 end |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
139 local a_conference = a:get_child("conference", namespace); |
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
140 local b_conference = b:get_child("conference", namespace); |
4739 | 141 local a_nick = a_conference:get_child_text("nick"); |
142 local b_nick = b_conference:get_child_text("nick"); | |
143 local a_password = a_conference:get_child_text("password"); | |
144 local b_password = b_conference:get_child_text("password"); | |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 return (a.attr.id == b.attr.id and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 a_conference.attr.name == b_conference.attr.name and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 a_conference.attr.autojoin == b_conference.attr.autojoin and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 a_nick == b_nick and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 a_password == b_password); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
152 local function publish_to_pep(jid, bookmarks, synchronise) |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 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
|
154 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 if #bookmarks.tags == 0 then |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
156 if synchronise then |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
157 -- If we set zero legacy bookmarks, purge the bookmarks 2 node. |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
158 module:log("debug", "No bookmark in the set, purging instead."); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
159 return service:purge(namespace, jid, true); |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
160 else |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
161 return true; |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
162 end |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 -- Retrieve the current bookmarks2. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 module:log("debug", "Retrieving the current bookmarks 2."); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
167 local has_bookmarks2, ret = service:get_items(namespace, jid); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 local bookmarks2; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 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
|
170 module:log("debug", "Got item-not-found, assuming it was empty until now, creating."); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
171 local ok, err = service:create(namespace, jid, default_options); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 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
|
174 return ok, err; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 bookmarks2 = {}; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 elseif not has_bookmarks2 then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 module:log("debug", "Got %s error, aborting.", ret); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 return false, ret; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 module:log("debug", "Got existing bookmarks2."); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 bookmarks2 = ret; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 -- 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
|
186 local to_remove = {}; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 for i in ipairs(bookmarks2) do |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 to_remove[bookmarks2[i]] = true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 end |
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 for bookmark in bookmarks:childtags("conference", "storage:bookmarks") do |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 -- Create the new conference element by copying everything from the legacy one. |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
193 local conference = st.stanza("conference", { xmlns = namespace }); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 conference.attr.name = bookmark.attr.name; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 conference.attr.autojoin = bookmark.attr.autojoin; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 local nick = bookmark:get_child_text("nick", "storage:bookmarks"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 if nick ~= nil then |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
198 conference:text_tag("nick", nick):up(); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 local password = bookmark:get_child_text("password", "storage:bookmarks"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 if password ~= nil then |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
202 conference:text_tag("password", password):up(); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 -- Create its wrapper. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 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
|
207 :add_child(conference); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 -- 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
|
210 if compare_bookmark2(item, bookmarks2[bookmark.attr.jid]) then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 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
|
212 to_remove[bookmark.attr.jid] = nil; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 if bookmarks2[bookmark.attr.jid] == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 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
|
216 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 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
|
218 to_remove[bookmark.attr.jid] = nil; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 end |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
220 local ok, err = service:publish(namespace, jid, bookmark.attr.jid, item, default_options); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 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
|
223 return ok, err; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 -- Now handle retracting items that have been removed. |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
229 if synchronise then |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
230 for id in pairs(to_remove) do |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
231 module:log("debug", "Item %s removed from bookmarks.", id); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
232 local ok, err = service:retract(namespace, jid, id, st.stanza("retract", { id = id })); |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
233 if not ok then |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
234 module:log("error", "Retracting item %s failed: %s", id, err); |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
235 return ok, err; |
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
236 end |
3677
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 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
242 -- Synchronise legacy PEP to PEP. |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
243 local function on_publish_legacy_pep(event) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
244 local stanza, session = event.stanza, event.origin; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
245 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
246 if pubsub == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
247 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
248 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
249 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
250 local publish = pubsub:get_child("publish"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
251 if publish == nil or publish.attr.node ~= "storage:bookmarks" then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
252 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
253 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
254 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
255 local item = publish:get_child("item"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
256 if item == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
257 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
258 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
259 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
260 -- Here we ignore the item id, it’ll be generated as 'current' anyway. |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
261 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
262 local bookmarks = item:get_child("storage", "storage:bookmarks"); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
263 if bookmarks == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
264 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
265 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
266 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
267 -- We also ignore the publish-options. |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
268 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
269 module:log("debug", "Legacy PEP bookmarks set by client, publishing to PEP."); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
270 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
271 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
272 if not ok then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
273 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
274 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
275 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
276 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
277 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
278 session.send(st.reply(stanza)); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
279 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
280 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
281 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 -- Synchronise Private XML to PEP. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
283 local function on_publish_private_xml(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
284 local stanza, session = event.stanza, event.origin; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 local query = stanza:get_child("query", "jabber:iq:private"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
286 if query == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
287 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
288 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
289 |
3742
05bca7a771d6
mod_bookmarks2: Remove unused variables.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3741
diff
changeset
|
290 local bookmarks = query:get_child("storage", "storage:bookmarks"); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 if bookmarks == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
292 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
295 module:log("debug", "Private bookmarks set by client, publishing to PEP."); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
296 |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
297 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 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
|
300 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
|
301 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 session.send(st.reply(stanza)); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 local function migrate_legacy_bookmarks(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 local session = event.session; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 local username = session.username; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
311 local service = mod_pep.get_pep_service(username); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 local jid = username.."@"..session.host; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
313 |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
314 local ok, ret = service:get_items("storage:bookmarks", session.full_jid); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
315 if ok then |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
316 module:log("debug", "Legacy PEP bookmarks found for %s, migrating.", jid); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
317 local failed = false; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
318 for _, item_id in ipairs(ret) do |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
319 local item = ret[item_id]; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
320 if item.attr.id ~= "current" then |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
321 module:log("warn", "Legacy PEP bookmarks for %s isn’t using 'current' as its id: %s", jid, item.attr.id); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
322 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
323 local bookmarks = item:get_child("storage", "storage:bookmarks"); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
324 module:log("debug", "Got legacy PEP bookmarks of %s: %s", jid, bookmarks); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
325 |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
326 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
327 if not ok then |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
328 module:log("error", "Failed to store legacy PEP bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
329 failed = true; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
330 break; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
331 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
332 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
333 if not failed then |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
334 module:log("debug", "Successfully migrated legacy PEP bookmarks of %s to bookmarks 2, attempting deletion of the node.", jid); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
335 local ok, err = service:delete("storage:bookmarks", jid); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
336 if not ok then |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
337 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", jid, err); |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
338 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
339 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
340 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
341 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
342 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
|
343 if not data then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 module:log("debug", "No existing legacy bookmarks for %s, migration already done: %s", jid, err); |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
345 local ok, ret2 = service:get_items(namespace, session.full_jid); |
4279
776eacd233b5
mod_bookmarks2: Fix luacheck warning
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3743
diff
changeset
|
346 if not ok or not ret2 then |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
347 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
|
348 module:fire_event("bookmarks/empty", { session = session }); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
349 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
350 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
351 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
352 local bookmarks = st.deserialize(data); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
353 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
|
354 |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
355 module:log("debug", "Going to store legacy bookmarks to bookmarks 2 %s.", jid); |
3739
1ed3d86eeaed
mod_bookmarks2: Don’t purge or remove inexistant items when synchronising existing Private XML data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3738
diff
changeset
|
356 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
357 if not ok then |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
358 module:log("error", "Failed to store legacy bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
359 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
360 end |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
361 module:log("debug", "Stored legacy bookmarks to bookmarks 2 for %s.", jid); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
362 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 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
|
364 if not ok then |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
365 module:log("error", "Failed to remove legacy bookmarks of %s: %s", jid, err); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
366 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
367 end |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
368 module:log("debug", "Removed legacy bookmarks of %s, migration done!", jid); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
369 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 local function on_node_created(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 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
|
373 if node ~= "storage:bookmarks" then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
375 end |
3743
5eab799b5fa4
mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3742
diff
changeset
|
376 |
5eab799b5fa4
mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3742
diff
changeset
|
377 module:log("debug", "Something tried to create legacy PEP bookmarks for %s.", actor); |
5eab799b5fa4
mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3742
diff
changeset
|
378 local ok, err = service:delete("storage:bookmarks", actor); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
379 if not ok then |
3743
5eab799b5fa4
mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3742
diff
changeset
|
380 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", actor, err); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
381 end |
3743
5eab799b5fa4
mod_bookmarks2: Delete legacy PEP bookmarks whenever they get recreated, to prevent them from being used.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3742
diff
changeset
|
382 module:log("debug", "Legacy PEP bookmarks node of %s deleted.", actor); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
383 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
384 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
385 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
|
386 if event.stanza.attr.type == "get" then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
387 return on_retrieve_private_xml(event); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
388 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
389 return on_publish_private_xml(event); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
390 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
391 end, 1); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
392 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function (event) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
393 if event.stanza.attr.type == "get" then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
394 return on_retrieve_legacy_pep(event); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
395 else |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
396 return on_publish_legacy_pep(event); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
397 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
398 end, 1); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
399 module:hook("resource-bind", migrate_legacy_bookmarks); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
400 module:handle_items("pep-service", function (event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
401 local service = event.item.service; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
402 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
|
403 end, function () end, true); |