Mercurial > prosody-modules
annotate mod_bookmarks2/mod_bookmarks2.lua @ 4890:347894e08b4f
mod_bookmarks2: Remove conflict check with mod_bookmarks
Should no longer be needed and causes trouble when mod_bookmarks
(community) redirects to mod_bookmarks2
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 09 Feb 2022 18:10:27 +0100 |
parents | a1181413a0eb |
children | a8e9949a6ad2 |
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 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 local jid_split = require "util.jid".split; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 local mod_pep = module:depends "pep"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 local private_storage = module:open_store("private", "map"); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 |
4640
d835cb7d2b47
mod_bookmarks2: Update namespace to :1
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4639
diff
changeset
|
8 local namespace = "urn:xmpp:bookmarks:1"; |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
9 local namespace_private = "jabber:iq:private"; |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
10 local namespace_legacy = "storage:bookmarks"; |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
11 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 local default_options = { |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ["persist_items"] = true; |
4719
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
14 ["max_items"] = "max"; |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 ["send_last_published_item"] = "never"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 ["access_model"] = "whitelist"; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 }; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 |
4848 | 19 if not pcall(mod_pep.check_node_config, nil, nil, default_options) then |
4719
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
20 -- 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
|
21 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
|
22 default_options["max_items"] = module:get_option_number("pep_max_items", 256); |
4866
a1181413a0eb
mod_bookmarks2: Skip send_last_published_item (unavailable in 0.11) (thanks carlos)
Kim Alvefur <zash@zash.se>
parents:
4850
diff
changeset
|
23 default_options["send_last_published_item"] = nil; -- not available in 0.11 |
4719
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
24 end |
5a06c711649c
mod_bookmarks2: Use max_items='max' on trunk, with fallback
Kim Alvefur <zash@zash.se>
parents:
4688
diff
changeset
|
25 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 module:hook("account-disco-info", function (event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 -- 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
|
28 event.reply:tag("feature", { var = namespace.."#compat" }):up(); |
4835
60b2dbe032c0
mod_bookmarks2: Finally add the #compat-pep feature!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4834
diff
changeset
|
29 event.reply:tag("feature", { var = namespace.."#compat-pep" }):up(); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 end); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 |
4838
fd2e48d4ac94
mod_bookmarks2: Advertise XEP-0049 support
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4837
diff
changeset
|
32 -- This must be declared on the domain JID, not the account JID. Note that |
fd2e48d4ac94
mod_bookmarks2: Advertise XEP-0049 support
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4837
diff
changeset
|
33 -- this isn’t defined in the XEP. |
fd2e48d4ac94
mod_bookmarks2: Advertise XEP-0049 support
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4837
diff
changeset
|
34 module:add_feature(namespace_private); |
fd2e48d4ac94
mod_bookmarks2: Advertise XEP-0049 support
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4837
diff
changeset
|
35 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
36 local function generate_legacy_storage(items) |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
37 local storage = st.stanza("storage", { xmlns = namespace_legacy }); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
38 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
|
39 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
|
40 local bookmark = item:get_child("conference", namespace); |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
41 local conference = st.stanza("conference", { |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
42 jid = item.attr.id, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
43 name = bookmark.attr.name, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
44 autojoin = bookmark.attr.autojoin, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
45 }); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
46 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
|
47 if nick ~= nil then |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
48 conference:text_tag("nick", nick):up(); |
4834
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 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
|
51 if password ~= nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
52 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
|
53 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
54 storage:add_child(conference); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
55 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
56 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
57 return storage; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
58 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
59 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 if pubsub == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
64 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
65 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
66 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
67 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
|
68 if items == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
69 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
70 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
71 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
72 local node = items.attr.node; |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
73 if node ~= namespace_legacy then |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
74 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
75 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
76 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
77 local username = session.username; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 if not ok then |
4845
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
82 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
83 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
84 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
85 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
86 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
87 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
|
88 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
89 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
|
90 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
|
91 :tag("pubsub", {xmlns = "http://jabber.org/protocol/pubsub"}) |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
92 :tag("items", {node = namespace_legacy}) |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
93 :tag("item", {id = "current"}) |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
94 :add_child(storage)); |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
95 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
96 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
97 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 local function on_retrieve_private_xml(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 local stanza, session = event.stanza, event.origin; |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
100 local query = stanza:get_child("query", namespace_private); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 if query == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
105 local bookmarks = query:get_child("storage", namespace_legacy); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 if bookmarks == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 module:log("debug", "Getting private bookmarks: %s", bookmarks); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 local username = session.username; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 local jid = username.."@"..session.host; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 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
|
115 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
|
116 if not ok then |
4845
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
117 if ret == "item-not-found" then |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
118 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid); |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
119 session.send(st.reply(stanza):add_child(query)); |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
120 else |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
121 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
122 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrive bookmarks from PEP")); |
6e17df6becec
mod_bookmarks2: Actually fix the right wrong codepath
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4844
diff
changeset
|
123 end |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
127 local storage = generate_legacy_storage(ret); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 module:log("debug", "Sending back private for %s: %s", jid, storage); |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
130 session.send(st.reply(stanza):query(namespace_private):add_child(storage)); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 local function compare_bookmark2(a, b) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 if a == nil or b == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 return false; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 end |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
138 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
|
139 local b_conference = b:get_child("conference", namespace); |
4739 | 140 local a_nick = a_conference:get_child_text("nick"); |
141 local b_nick = b_conference:get_child_text("nick"); | |
142 local a_password = a_conference:get_child_text("password"); | |
143 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
|
144 return (a.attr.id == b.attr.id and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 a_conference.attr.name == b_conference.attr.name and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 a_conference.attr.autojoin == b_conference.attr.autojoin and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 a_nick == b_nick and |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 a_password == b_password); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 |
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
|
151 local function publish_to_pep(jid, bookmarks, synchronise) |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 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
|
153 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 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
|
155 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
|
156 -- 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 end |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 -- Retrieve the current bookmarks2. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 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
|
166 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
|
167 local bookmarks2; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 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
|
173 return ok, err; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 bookmarks2 = {}; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 elseif not has_bookmarks2 then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 module:log("debug", "Got %s error, aborting.", ret); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 return false, ret; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 module:log("debug", "Got existing bookmarks2."); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 bookmarks2 = ret; |
4850
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
182 |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
183 local ok, err = service:get_node_config(namespace, jid); |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
184 if not ok then |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
185 module:log("error", "Retrieving bookmarks 2 node config failed: %s", err); |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
186 return ok, err; |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
187 end |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
188 |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
189 local options = err; |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
190 for key, value in pairs(default_options) do |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
191 if options[key] and options[key] ~= value then |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
192 module:log("warn", "Overriding bookmarks 2 configuration for %s, from %s to %s", jid, options[key], value); |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
193 options[key] = value; |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
194 end |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
195 end |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
196 |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
197 local ok, err = service:set_node_config(namespace, jid, options); |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
198 if not ok then |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
199 module:log("error", "Setting bookmarks 2 node config failed: %s", err); |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
200 return ok, err; |
9187a7adfc39
mod_bookmarks2: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4848
diff
changeset
|
201 end |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 -- 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
|
205 local to_remove = {}; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 for i in ipairs(bookmarks2) do |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 to_remove[bookmarks2[i]] = true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
210 for bookmark in bookmarks:childtags("conference", namespace_legacy) do |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 -- Create the new conference element by copying everything from the legacy one. |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
212 local conference = st.stanza("conference", { |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
213 xmlns = namespace, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
214 name = bookmark.attr.name, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
215 autojoin = bookmark.attr.autojoin, |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
216 }); |
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
217 local nick = bookmark:get_child_text("nick"); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 if nick ~= nil then |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
219 conference:text_tag("nick", nick):up(); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 end |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
221 local password = bookmark:get_child_text("password"); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 if password ~= nil then |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
223 conference:text_tag("password", password):up(); |
3677
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 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 -- Create its wrapper. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 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
|
228 :add_child(conference); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 -- 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
|
231 if compare_bookmark2(item, bookmarks2[bookmark.attr.jid]) then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 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
|
233 to_remove[bookmark.attr.jid] = nil; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 if bookmarks2[bookmark.attr.jid] == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 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
|
237 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 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
|
239 to_remove[bookmark.attr.jid] = nil; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 end |
4639
3da7cd77aca9
mod_bookmarks2: Factor namespace string into a variable
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4279
diff
changeset
|
241 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
|
242 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 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
|
244 return ok, err; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 -- 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 end |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
263 -- 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
|
264 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
|
265 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
|
266 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
|
267 if pubsub == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
268 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
269 end |
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 publish = pubsub:get_child("publish"); |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
272 if publish == nil or publish.attr.node ~= namespace_legacy then |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
273 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
274 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
275 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
276 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
|
277 if item == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
278 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
279 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
280 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
281 -- 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
|
282 |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
283 local bookmarks = item:get_child("storage", namespace_legacy); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
284 if bookmarks == nil then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
285 return; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
286 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
287 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
288 -- 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
|
289 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
290 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
|
291 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
292 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
|
293 if not ok then |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
294 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
|
295 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
|
296 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
297 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
298 |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
299 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
|
300 return true; |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
301 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
302 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 -- Synchronise Private XML to PEP. |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 local function on_publish_private_xml(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 local stanza, session = event.stanza, event.origin; |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
306 local query = stanza:get_child("query", namespace_private); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 if query == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
311 local bookmarks = query:get_child("storage", namespace_legacy); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 if bookmarks == nil then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
313 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
314 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
315 |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
316 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
|
317 |
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
|
318 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
|
319 if not ok then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
320 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
|
321 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
|
322 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
325 session.send(st.reply(stanza)); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
326 return true; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
327 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 local function migrate_legacy_bookmarks(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
330 local session = event.session; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
331 local username = session.username; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
332 local service = mod_pep.get_pep_service(username); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
333 local jid = username.."@"..session.host; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
334 |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
335 local ok, ret = service:get_items(namespace_legacy, session.full_jid); |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
336 if 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("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
|
338 local failed = false; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
339 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
|
340 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
|
341 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
|
342 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
|
343 end |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
344 local bookmarks = item:get_child("storage", namespace_legacy); |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
345 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
|
346 |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 failed = true; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
351 break; |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
352 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
353 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
354 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
|
355 module:log("debug", "Successfully migrated legacy PEP bookmarks of %s to bookmarks 2, attempting deletion of the node.", jid); |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
356 local ok, err = service:delete(namespace_legacy, jid); |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
357 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
|
358 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
|
359 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
360 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
361 end |
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
362 |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 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
|
364 if not data then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
365 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
|
366 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
|
367 if not ok or not ret2 then |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
368 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
|
369 module:fire_event("bookmarks/empty", { session = session }); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
373 local bookmarks = st.deserialize(data); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 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
|
375 |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
381 end |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
382 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
|
383 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
388 end |
3741
33b3e2387a10
mod_bookmarks2: Also migrate legacy PEP bookmarks (current XEP-0048).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
3740
diff
changeset
|
389 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
|
390 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
391 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
392 local function on_node_created(event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
393 local service, node, actor = event.service, event.node, event.actor; |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
394 if node ~= namespace_legacy then |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
395 return; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
396 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
|
397 |
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
|
398 module:log("debug", "Something tried to create legacy PEP bookmarks for %s.", actor); |
4837
1f1acb7f3c10
mod_bookmarks2: Use constants for namespaces
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4835
diff
changeset
|
399 local ok, err = service:delete(namespace_legacy, actor); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 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
|
404 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
405 |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
406 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
|
407 if event.stanza.attr.type == "get" then |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
408 return on_retrieve_private_xml(event); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
409 else |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
410 return on_publish_private_xml(event); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
411 end |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
412 end, 1); |
4834
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 else |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
417 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
|
418 end |
7ed2467c9bb5
mod_bookmarks2: Add simple support for legacy PEP queries
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
4739
diff
changeset
|
419 end, 1); |
3677
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
420 module:hook("resource-bind", migrate_legacy_bookmarks); |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
421 module:handle_items("pep-service", function (event) |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
422 local service = event.item.service; |
90f88a643973
mod_bookmarks2: Add new module.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
423 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
|
424 end, function () end, true); |