Software /
code /
prosody
Changeset
10046:0bc291a5734a
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 10 Jun 2019 13:22:22 +0200 |
parents | 10045:6714578cfd6e (diff) 10044:4fd27023224a (current diff) |
children | 10047:177a8b92204b |
files | doc/coding_style.txt net/connlisteners.lua plugins/mod_pep.lua tools/migration/migrator/mtools.lua tools/migration/migrator/prosody_files.lua tools/migration/migrator/prosody_sql.lua |
diffstat | 1 files changed, 40 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pep.lua Mon Jun 03 20:51:15 2019 +0200 +++ b/plugins/mod_pep.lua Mon Jun 10 13:22:22 2019 +0200 @@ -91,6 +91,21 @@ 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() @@ -124,7 +139,6 @@ if kind == "retract" then kind = "items"; -- XEP-0060 signals retraction in an <items> container end - if item then item = st.clone(item); item.attr.xmlns = nil; -- Clear the pubsub namespace @@ -144,22 +158,7 @@ message:add_child(item); end - local broadcast_to = {}; for jid in pairs(jids) do - broadcast_to[jid] = true; - end - - 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 - - for jid in pairs(broadcast_to) do module:log("debug", "Sending notification to %s from %s: %s", jid, user_bare, tostring(item)); message.attr.to = jid; module:send(message); @@ -168,6 +167,21 @@ 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); @@ -226,6 +240,11 @@ 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; @@ -240,6 +259,7 @@ module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq); module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq); + local function get_caps_hash_from_presence(stanza, current) local t = stanza.attr.type; if not t then @@ -288,9 +308,12 @@ 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:may(node, recipient, "subscribe") then + if service:add_subscription(node, recipient, recipient, { presence = true }) then resend_last_item(recipient, node, service); end end