aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-06-10 13:57:09 +0200
committerKim Alvefur <zash@zash.se>2019-06-10 13:57:09 +0200
commitdfdc2502ee41533db43d1aa4d0bc38bc44973ac1 (patch)
treee7ff42ce8d5a73612e7d0c37e18ebf323b43a96e /plugins
parent0307e6754aec0011923b2d010103a8c81146cb13 (diff)
downloadprosody-dfdc2502ee41533db43d1aa4d0bc38bc44973ac1.tar.gz
prosody-dfdc2502ee41533db43d1aa4d0bc38bc44973ac1.zip
mod_pep: Handle presence subscriptions in filter (fixes #1372)
Take two on 045209b41b3a
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_pep.lua51
1 files changed, 17 insertions, 34 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 7a4aac2b..12be41a2 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -90,21 +90,6 @@ local function nodestore(username)
return data, err;
end
function store:set(node, data)
- if data then
- -- Save the data without subscriptions
- local subscribers = {};
- for jid, sub in pairs(data.subscribers) do
- if type(sub) ~= "table" or not sub.presence then
- subscribers[jid] = sub;
- end
- end
- data = {
- name = data.name;
- config = data.config;
- affiliations = data.affiliations;
- subscribers = subscribers;
- };
- end
return node_config:set(username, node, data);
end
function store:users()
@@ -160,18 +145,23 @@ 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
+local function get_subscriber_filter(username)
+ return function (jids, node)
+ local broadcast_to = {};
+ for jid, opts in pairs(jids) do
+ broadcast_to[jid] = opts;
+ end
- for recipient, nodes in pairs(service_recipients) do
- if nodes:contains(node) then
- service:add_subscription(node, recipient, recipient, { presence = true });
+ local service_recipients = recipients[username];
+ if service_recipients then
+ local service = services[username];
+ for recipient, nodes in pairs(service_recipients) do
+ if nodes:contains(node) and service:may(node, recipient, "subscribe") then
+ broadcast_to[recipient] = true;
+ end
+ end
end
+ return broadcast_to;
end
end
@@ -196,6 +186,7 @@ function get_pep_service(username)
nodestore = nodestore(username);
itemstore = simple_itemstore(username);
broadcaster = get_broadcaster(username);
+ subscriber_filter = get_subscriber_filter(username);
itemcheck = is_item_stanza;
get_affiliation = function (jid)
if jid_bare(jid) == user_bare then
@@ -233,11 +224,6 @@ 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;
@@ -303,12 +289,9 @@ local function update_subscriptions(recipient, service_name, nodes)
end
local service = get_pep_service(service_name);
- for node in current - nodes do
- service:remove_subscription(node, recipient, recipient);
- end
for node in nodes - current do
- if service:add_subscription(node, recipient, recipient, { presence = true }) then
+ if service:may(node, recipient, "subscribe") then
resend_last_item(recipient, node, service);
end
end