Software /
code /
prosody
Annotate
plugins/mod_bookmarks.lua @ 12787:3735ad8d6f8e 0.12
mod_admin_shell: Ensure connection exists to get port from (fixes #1777)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Oct 2022 16:19:39 +0200 |
parent | 12593:1832b6c9c6ed |
child | 12977:74b9e05af71e |
rev | line source |
---|---|
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 local mm = require "core.modulemanager"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 if mm.get_modules_for_host(module.host):contains("bookmarks2") then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 error("mod_bookmarks and mod_bookmarks2 are conflicting, please disable one of them.", 0); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 local st = require "util.stanza"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 local jid_split = require "util.jid".split; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 local mod_pep = module:depends "pep"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 local private_storage = module:open_store("private", "map"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 local namespace = "urn:xmpp:bookmarks:1"; |
12177
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
13 local namespace_old = "urn:xmpp:bookmarks:0"; |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 local namespace_private = "jabber:iq:private"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 local namespace_legacy = "storage:bookmarks"; |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
16 local xmlns_pubsub = "http://jabber.org/protocol/pubsub"; |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
18 local default_options = { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 ["persist_items"] = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 ["max_items"] = "max"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 ["send_last_published_item"] = "never"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 ["access_model"] = "whitelist"; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 }; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
24 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
25 module:hook("account-disco-info", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 -- This Time it’s Serious! |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 event.reply:tag("feature", { var = namespace.."#compat" }):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 event.reply:tag("feature", { var = namespace.."#compat-pep" }):up(); |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
29 |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
30 -- COMPAT XEP-0411 |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
31 event.reply:tag("feature", { var = "urn:xmpp:bookmarks-conversion:0" }):up(); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 end); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 -- This must be declared on the domain JID, not the account JID. Note that |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 -- this isn’t defined in the XEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 module:add_feature(namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
37 |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
38 |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 local function generate_legacy_storage(items) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 local storage = st.stanza("storage", { xmlns = namespace_legacy }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 for _, item_id in ipairs(items) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 local item = items[item_id]; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 local bookmark = item:get_child("conference", namespace); |
12178
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
44 if not bookmark then |
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
45 module:log("warn", "Invalid bookmark published: expected {%s}conference, got {%s}%s", namespace, |
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
46 |
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
47 item.tags[1] and item.tags[1].attr.xmlns, item.tags[1] and item.tags[1].name); |
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
48 end |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 local conference = st.stanza("conference", { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 jid = item.attr.id, |
12178
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
51 name = bookmark and bookmark.attr.name, |
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
52 autojoin = bookmark and bookmark.attr.autojoin, |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 }); |
12178
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
54 local nick = bookmark and bookmark:get_child_text("nick"); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 if nick ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 conference:text_tag("nick", nick):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 end |
12178
0aa99a6dfb3e
mod_bookmarks: Fix traceback on attempt to convert invalid bookmark
Kim Alvefur <zash@zash.se>
parents:
12177
diff
changeset
|
58 local password = bookmark and bookmark:get_child_text("password"); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 if password ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 conference:text_tag("password", password):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 storage:add_child(conference); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 return storage; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 local function on_retrieve_legacy_pep(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 if pubsub == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 local items = pubsub:get_child("items"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 if items == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 local node = items.attr.node; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 if node ~= namespace_legacy then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 local ok, ret = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 if not ok then |
12593
1832b6c9c6ed
mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
Kim Alvefur <zash@zash.se>
parents:
12259
diff
changeset
|
90 if ret == "item-not-found" then |
1832b6c9c6ed
mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
Kim Alvefur <zash@zash.se>
parents:
12259
diff
changeset
|
91 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid); |
1832b6c9c6ed
mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
Kim Alvefur <zash@zash.se>
parents:
12259
diff
changeset
|
92 else |
1832b6c9c6ed
mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
Kim Alvefur <zash@zash.se>
parents:
12259
diff
changeset
|
93 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
1832b6c9c6ed
mod_bookmarks: Reduce error about not having bookmarks to debug (thanks tom)
Kim Alvefur <zash@zash.se>
parents:
12259
diff
changeset
|
94 end |
12259
57792ed670e7
mod_bookmarks: Fix typos in stanza error messages [codespell]
Kim Alvefur <zash@zash.se>
parents:
12178
diff
changeset
|
95 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrieve bookmarks from PEP")); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 local storage = generate_legacy_storage(ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 module:log("debug", "Sending back legacy PEP for %s: %s", jid, storage); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 session.send(st.reply(stanza) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 :tag("pubsub", {xmlns = "http://jabber.org/protocol/pubsub"}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 :tag("items", {node = namespace_legacy}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 :tag("item", {id = "current"}) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 :add_child(storage)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 local function on_retrieve_private_xml(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 local query = stanza:get_child("query", namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 if query == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 local bookmarks = query:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 module:log("debug", "Getting private bookmarks: %s", bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 local ok, ret = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 if ret == "item-not-found" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 module:log("debug", "Got no PEP bookmarks item for %s, returning empty private bookmarks", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 session.send(st.reply(stanza):add_child(query)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 module:log("error", "Failed to retrieve PEP bookmarks of %s: %s", jid, ret); |
12259
57792ed670e7
mod_bookmarks: Fix typos in stanza error messages [codespell]
Kim Alvefur <zash@zash.se>
parents:
12178
diff
changeset
|
134 session.send(st.error_reply(stanza, "cancel", ret, "Failed to retrieve bookmarks from PEP")); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 local storage = generate_legacy_storage(ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 module:log("debug", "Sending back private for %s: %s", jid, storage); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 session.send(st.reply(stanza):query(namespace_private):add_child(storage)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 local function compare_bookmark2(a, b) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 if a == nil or b == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 return false; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 local a_conference = a:get_child("conference", namespace); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 local b_conference = b:get_child("conference", namespace); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 local a_nick = a_conference:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 local b_nick = b_conference:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 local a_password = a_conference:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 local b_password = b_conference:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 return (a.attr.id == b.attr.id and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 a_conference.attr.name == b_conference.attr.name and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 a_conference.attr.autojoin == b_conference.attr.autojoin and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 a_nick == b_nick and |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 a_password == b_password); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 local function publish_to_pep(jid, bookmarks, synchronise) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 local service = mod_pep.get_pep_service(jid_split(jid)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 if #bookmarks.tags == 0 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 if synchronise then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 -- If we set zero legacy bookmarks, purge the bookmarks 2 node. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 module:log("debug", "No bookmark in the set, purging instead."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 return service:purge(namespace, jid, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 -- Retrieve the current bookmarks2. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 module:log("debug", "Retrieving the current bookmarks 2."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 local has_bookmarks2, ret = service:get_items(namespace, jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 local bookmarks2; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 if not has_bookmarks2 and ret == "item-not-found" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 module:log("debug", "Got item-not-found, assuming it was empty until now, creating."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 local ok, err = service:create(namespace, jid, default_options); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 module:log("error", "Creating bookmarks 2 node failed: %s", err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 bookmarks2 = {}; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 elseif not has_bookmarks2 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 module:log("debug", "Got %s error, aborting.", ret); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 return false, ret; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 module:log("debug", "Got existing bookmarks2."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 bookmarks2 = ret; |
12152
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
194 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
195 local ok, err = service:get_node_config(namespace, jid); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
196 if not ok then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
197 module:log("error", "Retrieving bookmarks 2 node config failed: %s", err); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
198 return ok, err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
199 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
200 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
201 local options = err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
202 for key, value in pairs(default_options) do |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
203 if options[key] and options[key] ~= value then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
204 module:log("warn", "Overriding bookmarks 2 configuration for %s, from %s to %s", jid, options[key], value); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
205 options[key] = value; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
206 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
207 end |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
208 |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
209 local ok, err = service:set_node_config(namespace, jid, options); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
210 if not ok then |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
211 module:log("error", "Setting bookmarks 2 node config failed: %s", err); |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
212 return ok, err; |
0939675955f1
mod_bookmarks: Override the node configuration if it was wrong
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12149
diff
changeset
|
213 end |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 -- Get a list of all items we may want to remove. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 local to_remove = {}; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 for i in ipairs(bookmarks2) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 to_remove[bookmarks2[i]] = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 for bookmark in bookmarks:childtags("conference", namespace_legacy) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 -- Create the new conference element by copying everything from the legacy one. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 local conference = st.stanza("conference", { |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 xmlns = namespace, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 name = bookmark.attr.name, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 autojoin = bookmark.attr.autojoin, |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 local nick = bookmark:get_child_text("nick"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 if nick ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 conference:text_tag("nick", nick):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 local password = bookmark:get_child_text("password"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 if password ~= nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 conference:text_tag("password", password):up(); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 -- Create its wrapper. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = bookmark.attr.jid }) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 :add_child(conference); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 -- Then publish it only if it’s a new one or updating a previous one. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 if compare_bookmark2(item, bookmarks2[bookmark.attr.jid]) then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 module:log("debug", "Item %s identical to the previous one, skipping.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 to_remove[bookmark.attr.jid] = nil; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 if bookmarks2[bookmark.attr.jid] == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 module:log("debug", "Item %s not existing previously, publishing.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
250 module:log("debug", "Item %s different from the previous one, publishing.", item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 to_remove[bookmark.attr.jid] = nil; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 local ok, err = service:publish(namespace, jid, bookmark.attr.jid, item, default_options); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 module:log("error", "Publishing item %s failed: %s", item.attr.id, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 -- Now handle retracting items that have been removed. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 if synchronise then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 for id in pairs(to_remove) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 module:log("debug", "Item %s removed from bookmarks.", id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
265 local ok, err = service:retract(namespace, jid, id, st.stanza("retract", { id = id })); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 module:log("error", "Retracting item %s failed: %s", id, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 return ok, err; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
273 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 -- Synchronise legacy PEP to PEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
276 local function on_publish_legacy_pep(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
277 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
278 local pubsub = stanza:get_child("pubsub", "http://jabber.org/protocol/pubsub"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
279 if pubsub == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
280 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
281 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
283 local publish = pubsub:get_child("publish"); |
12177
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
284 if publish == nil then return end |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
285 if publish.attr.node == namespace_old then |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
286 session.send(st.error_reply(stanza, "modify", "not-allowed", |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
287 "Your client does XEP-0402 version 0.3.0 but 0.4.0+ is required")); |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
288 return true; |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
289 end |
024cc878f472
mod_bookmarks: Block publishing to older XEP-0402 v0.3.0 node
Kim Alvefur <zash@zash.se>
parents:
12172
diff
changeset
|
290 if publish.attr.node ~= namespace_legacy then |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
292 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 local item = publish:get_child("item"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
295 if item == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
296 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
297 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 -- Here we ignore the item id, it’ll be generated as 'current' anyway. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
300 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
301 local bookmarks = item:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 -- We also ignore the publish-options. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 module:log("debug", "Legacy PEP bookmarks set by client, publishing to PEP."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
311 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
313 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
314 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
315 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
316 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
317 session.send(st.reply(stanza)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
319 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
320 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
321 -- Synchronise Private XML to PEP. |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
322 local function on_publish_private_xml(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 local stanza, session = event.stanza, event.origin; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 local query = stanza:get_child("query", namespace_private); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
325 if query == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
326 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
327 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 local bookmarks = query:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
330 if bookmarks == nil then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
331 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
332 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
333 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
334 module:log("debug", "Private bookmarks set by client, publishing to PEP."); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
335 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
336 local ok, err = publish_to_pep(session.full_jid, bookmarks, true); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
337 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
338 module:log("error", "Failed to publish to PEP bookmarks for %s@%s: %s", session.username, session.host, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
339 session.send(st.error_reply(stanza, "cancel", "internal-server-error", "Failed to store bookmarks to PEP")); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
340 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
341 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
342 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
343 session.send(st.reply(stanza)); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 return true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
345 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
346 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
347 local function migrate_legacy_bookmarks(event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
348 local session = event.session; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
349 local username = session.username; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
350 local service = mod_pep.get_pep_service(username); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
351 local jid = username.."@"..session.host; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
352 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
353 local ok, ret = service:get_items(namespace_legacy, session.full_jid); |
12172
2515033c2a74
mod_bookmarks: Skip migration of legacy data when empty
Kim Alvefur <zash@zash.se>
parents:
12171
diff
changeset
|
354 if ok and ret[1] then |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
355 module:log("debug", "Legacy PEP bookmarks found for %s, migrating.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
356 local failed = false; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
357 for _, item_id in ipairs(ret) do |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
358 local item = ret[item_id]; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
359 if item.attr.id ~= "current" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
360 module:log("warn", "Legacy PEP bookmarks for %s isn’t using 'current' as its id: %s", jid, item.attr.id); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
361 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
362 local bookmarks = item:get_child("storage", namespace_legacy); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 module:log("debug", "Got legacy PEP bookmarks of %s: %s", jid, bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
364 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
365 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
366 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
367 module:log("error", "Failed to store legacy PEP bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
368 failed = true; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
369 break; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 if not failed then |
12171
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
373 module:log("debug", "Successfully migrated legacy PEP bookmarks of %s to bookmarks 2, clearing items.", jid); |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
374 local ok, err = service:purge(namespace_legacy, jid, false); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
375 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
376 module:log("error", "Failed to delete legacy PEP bookmarks for %s: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
377 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
378 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
379 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
380 |
12171
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
381 local ok, current_legacy_config = service:get_node_config(namespace_legacy, jid); |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
382 if not ok or current_legacy_config["access_model"] ~= "whitelist" then |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
383 -- The legacy node must exist in order for the access model to apply to the |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
384 -- XEP-0411 COMPAT broadcasts (which bypass the pubsub service entirely), |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
385 -- so create or reconfigure it to be useless. |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
386 -- |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
387 -- FIXME It would be handy to have a publish model that prevents the owner |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
388 -- from publishing, but the affiliation takes priority |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
389 local config = { |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
390 ["persist_items"] = false; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
391 ["max_items"] = 1; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
392 ["send_last_published_item"] = "never"; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
393 ["access_model"] = "whitelist"; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
394 }; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
395 local ok, err; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
396 if ret == "item-not-found" then |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
397 ok, err = service:create(namespace_legacy, jid, config); |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
398 else |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
399 ok, err = service:set_node_config(namespace_legacy, jid, config); |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
400 end |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
401 if not ok then |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
402 module:log("error", "Setting legacy bookmarks node config failed: %s", err); |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
403 return ok, err; |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
404 end |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
405 end |
b2923a3b4e02
mod_bookmarks: Make sure legacy bookmarks node exists to hold access model
Kim Alvefur <zash@zash.se>
parents:
12170
diff
changeset
|
406 |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
407 local data, err = private_storage:get(username, "storage:storage:bookmarks"); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
408 if not data then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
409 module:log("debug", "No existing legacy bookmarks for %s, migration already done: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
410 local ok, ret2 = service:get_items(namespace, session.full_jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
411 if not ok or not ret2 then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
412 module:log("debug", "Additionally, no bookmarks 2 were existing for %s, assuming empty.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
413 module:fire_event("bookmarks/empty", { session = session }); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
414 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
415 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
416 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
417 local bookmarks = st.deserialize(data); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
418 module:log("debug", "Got legacy bookmarks of %s: %s", jid, bookmarks); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
419 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
420 module:log("debug", "Going to store legacy bookmarks to bookmarks 2 %s.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
421 local ok, err = publish_to_pep(session.full_jid, bookmarks, false); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
422 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
423 module:log("error", "Failed to store legacy bookmarks to bookmarks 2 for %s, aborting migration: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
424 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
425 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
426 module:log("debug", "Stored legacy bookmarks to bookmarks 2 for %s.", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
427 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
428 local ok, err = private_storage:set(username, "storage:storage:bookmarks", nil); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
429 if not ok then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
430 module:log("error", "Failed to remove legacy bookmarks of %s: %s", jid, err); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
431 return; |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
432 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
433 module:log("debug", "Removed legacy bookmarks of %s, migration done!", jid); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
434 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
435 |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
436 module:hook("iq/bare/jabber:iq:private:query", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
437 if event.stanza.attr.type == "get" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
438 return on_retrieve_private_xml(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
439 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
440 return on_publish_private_xml(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
441 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
442 end, 1); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
443 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
444 if event.stanza.attr.type == "get" then |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
445 return on_retrieve_legacy_pep(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
446 else |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
447 return on_publish_legacy_pep(event); |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
448 end |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
449 end, 1); |
12156
17cffaa78f48
mod_bookmarks: Add option for disabling upgrade of legacy bookmarks
Kim Alvefur <zash@zash.se>
parents:
12155
diff
changeset
|
450 if module:get_option_boolean("upgrade_legacy_bookmarks", true) then |
17cffaa78f48
mod_bookmarks: Add option for disabling upgrade of legacy bookmarks
Kim Alvefur <zash@zash.se>
parents:
12155
diff
changeset
|
451 module:hook("resource-bind", migrate_legacy_bookmarks); |
17cffaa78f48
mod_bookmarks: Add option for disabling upgrade of legacy bookmarks
Kim Alvefur <zash@zash.se>
parents:
12155
diff
changeset
|
452 end |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
453 -- COMPAT XEP-0411 Broadcast as per XEP-0048 + PEP |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
454 local function legacy_broadcast(event) |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
455 local service = event.service; |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
456 local ok, bookmarks = service:get_items(namespace, event.actor); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
457 if bookmarks == "item-not-found" then ok, bookmarks = true, {} end |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
458 if not ok then return end |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
459 local legacy_bookmarks_item = st.stanza("item", { xmlns = xmlns_pubsub; id = "current" }) |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
460 :add_child(generate_legacy_storage(bookmarks)); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
461 service:broadcast("items", namespace_legacy, { --[[ no subscribers ]] }, legacy_bookmarks_item, event.actor); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
462 end |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
463 local function broadcast_legacy_removal(event) |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
464 if event.node ~= namespace then return end |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
465 return legacy_broadcast(event); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
466 end |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
467 module:hook("presence/initial", function (event) |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
468 -- Broadcasts to all clients with legacy+notify, not just the one coming online. |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
469 -- Upgrade to XEP-0402 to avoid it |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
470 local service = mod_pep.get_pep_service(event.origin.username); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
471 legacy_broadcast({ service = service, actor = event.origin.full_jid }); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
472 end); |
12148
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
473 module:handle_items("pep-service", function (event) |
b63bb2c4b6d9
mod_bookmarks: Import mod_bookmarks2 from prosody-modules @ ad7767a9f3ea
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
474 local service = event.item.service; |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
475 module:hook_object_event(service.events, "item-published/" .. namespace, legacy_broadcast); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
476 module:hook_object_event(service.events, "item-retracted", broadcast_legacy_removal); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
477 module:hook_object_event(service.events, "node-purged", broadcast_legacy_removal); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
478 module:hook_object_event(service.events, "node-deleted", broadcast_legacy_removal); |
12155
ae5988739990
mod_bookmarks: Unhook PEP service objects on removal from cache
Kim Alvefur <zash@zash.se>
parents:
12152
diff
changeset
|
479 end, function (event) |
ae5988739990
mod_bookmarks: Unhook PEP service objects on removal from cache
Kim Alvefur <zash@zash.se>
parents:
12152
diff
changeset
|
480 local service = event.item.service; |
12170
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
481 module:unhook_object_event(service.events, "item-published/" .. namespace, legacy_broadcast); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
482 module:unhook_object_event(service.events, "item-retracted", broadcast_legacy_removal); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
483 module:unhook_object_event(service.events, "node-purged", broadcast_legacy_removal); |
750abaf99baf
mod_bookmarks: Broadcast notifications per XEP-0048 and XEP-0411
Kim Alvefur <zash@zash.se>
parents:
12156
diff
changeset
|
484 module:unhook_object_event(service.events, "node-deleted", broadcast_legacy_removal); |
12155
ae5988739990
mod_bookmarks: Unhook PEP service objects on removal from cache
Kim Alvefur <zash@zash.se>
parents:
12152
diff
changeset
|
485 end, true); |