aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pep.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-10-20 20:22:55 +0200
committerKim Alvefur <zash@zash.se>2018-10-20 20:22:55 +0200
commit14a5504cbe331983c57dd093bd5fede4082ade5b (patch)
tree1825f3f3d4bf8054283fcb8144a35633e6bd1277 /plugins/mod_pep.lua
parentdb2de29aa945cd9206331622a71abc2279af04dc (diff)
downloadprosody-14a5504cbe331983c57dd093bd5fede4082ade5b.tar.gz
prosody-14a5504cbe331983c57dd093bd5fede4082ade5b.zip
mod_pep: Add automatic subscriptions on node creation (fixes #1222)
Replaces automatic node creation on subscription, since this casues problems when trying to keep nodes private or other specific settings.
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r--plugins/mod_pep.lua22
1 files changed, 21 insertions, 1 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 069d67f2..681e5be8 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -158,6 +158,21 @@ local function get_broadcaster(username)
return simple_broadcast;
end
+local function on_node_creation(event)
+ local service = event.service;
+ local node = event.node;
+ local username = service.config.pep_username;
+
+ local service_recipients = recipients[username];
+ if not service_recipients then return; end
+
+ for recipient, nodes in pairs(service_recipients) do
+ if nodes:contains(node) then
+ service:add_subscription(node, recipient, recipient, { presence = true });
+ end
+ end
+end
+
function get_pep_service(username)
module:log("debug", "get_pep_service(%q)", username);
local user_bare = jid_join(username, host);
@@ -174,7 +189,7 @@ function get_pep_service(username)
};
autocreate_on_publish = true;
- autocreate_on_subscribe = true;
+ autocreate_on_subscribe = false;
nodestore = nodestore(username);
itemstore = simple_itemstore(username);
@@ -216,6 +231,11 @@ function get_pep_service(username)
return service;
end
+module:hook("item-added/pep-service", function (event)
+ local service = event.item.service;
+ module:hook_object_event(service.events, "node-created", on_node_creation);
+end);
+
function handle_pubsub_iq(event)
local origin, stanza = event.origin, event.stanza;
local service_name = origin.username;