Mercurial > prosody-modules
comparison mod_bookmarks/mod_bookmarks.lua @ 3294:947790ec4406
mod_bookmarks: Ensure the configuration is correct even with create-on-subscribe.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 31 Aug 2018 22:17:19 +0200 |
parents | 87769f53fdc8 |
children | 303b17ec8264 |
comparison
equal
deleted
inserted
replaced
3293:f728c8c42860 | 3294:947790ec4406 |
---|---|
1 local st = require "util.stanza"; | 1 local st = require "util.stanza"; |
2 local jid_split = require "util.jid".split; | 2 local jid_split = require "util.jid".split; |
3 | 3 |
4 local mod_pep = module:depends "pep"; | 4 local mod_pep = module:depends "pep"; |
5 local private_storage = module:open_store("private", "map"); | 5 local private_storage = module:open_store("private", "map"); |
6 | |
7 local default_options = { | |
8 ["persist_items"] = true; | |
9 ["access_model"] = "whitelist"; | |
10 }; | |
6 | 11 |
7 module:hook("account-disco-info", function (event) | 12 module:hook("account-disco-info", function (event) |
8 event.reply:tag("feature", { var = "urn:xmpp:bookmarks-conversion:0" }):up(); | 13 event.reply:tag("feature", { var = "urn:xmpp:bookmarks-conversion:0" }):up(); |
9 end); | 14 end); |
10 | 15 |
46 | 51 |
47 function publish_to_pep(jid, bookmarks) | 52 function publish_to_pep(jid, bookmarks) |
48 local service = mod_pep.get_pep_service(jid_split(jid)); | 53 local service = mod_pep.get_pep_service(jid_split(jid)); |
49 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) | 54 local item = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" }) |
50 :add_child(bookmarks); | 55 :add_child(bookmarks); |
51 local options = { | 56 return service:publish("storage:bookmarks", jid, "current", item, default_options); |
52 ["persist_items"] = true; | |
53 ["access_model"] = "whitelist"; | |
54 }; | |
55 return service:publish("storage:bookmarks", jid, "current", item, options); | |
56 end | 57 end |
57 | 58 |
58 -- Synchronise Private XML to PEP. | 59 -- Synchronise Private XML to PEP. |
59 local function on_publish_private_xml(event) | 60 local function on_publish_private_xml(event) |
60 local stanza, session = event.stanza, event.origin; | 61 local stanza, session = event.stanza, event.origin; |
121 | 122 |
122 local function on_item_published(event) | 123 local function on_item_published(event) |
123 module:fire_event("bookmarks/updated", event); | 124 module:fire_event("bookmarks/updated", event); |
124 end | 125 end |
125 | 126 |
127 local function on_node_created(event) | |
128 local service, node, actor = event.service, event.node, event.actor; | |
129 if node ~= "storage:bookmarks" then | |
130 return; | |
131 end | |
132 local node_config = service.nodes[node].config; | |
133 for config_field, value in pairs(default_options) do | |
134 node_config[config_field] = value; | |
135 end | |
136 end | |
137 | |
126 module:hook("iq-get/bare/jabber:iq:private:query", on_retrieve_private_xml); | 138 module:hook("iq-get/bare/jabber:iq:private:query", on_retrieve_private_xml); |
127 module:hook("iq-set/bare/jabber:iq:private:query", on_publish_private_xml); | 139 module:hook("iq-set/bare/jabber:iq:private:query", on_publish_private_xml); |
128 module:hook("resource-bind", on_resource_bind); | 140 module:hook("resource-bind", on_resource_bind); |
129 module:hook("item-published/storage:bookmarks", on_item_published); | 141 module:hook("item-published/storage:bookmarks", on_item_published); |
142 module:hook("node-created", on_node_created); |