aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_blocklist.lua9
-rw-r--r--plugins/mod_pep.lua59
-rw-r--r--plugins/muc/muc.lib.lua24
3 files changed, 70 insertions, 22 deletions
diff --git a/plugins/mod_blocklist.lua b/plugins/mod_blocklist.lua
index 2193a093..cf8aad80 100644
--- a/plugins/mod_blocklist.lua
+++ b/plugins/mod_blocklist.lua
@@ -128,6 +128,7 @@ local function edit_blocklist(event)
-- > only if the contact is allowed to receive presence notifications [...]
-- So contacts we need to do that for are added to the set below.
local send_unavailable = is_blocking and {};
+ local send_available = not is_blocking and {};
-- Because blocking someone currently also blocks the ability to reject
-- subscription requests, we'll preemptively reject such
@@ -147,6 +148,8 @@ local function edit_blocklist(event)
elseif is_contact_pending_in(username, module.host, jid) then
remove_pending[jid] = true;
end
+ elseif is_contact_subscribed(username, module.host, jid) then
+ send_available[jid] = true;
end
end
@@ -186,6 +189,7 @@ local function edit_blocklist(event)
if is_blocking then
for jid in pairs(send_unavailable) do
+ -- Check that this JID isn't already blocked, i.e. this is not a change
if not blocklist[jid] then
for _, session in pairs(sessions[username].sessions) do
if session.presence then
@@ -203,6 +207,11 @@ local function edit_blocklist(event)
save_roster(username, module.host, roster);
-- Not much we can do about save failing here
end
+ else
+ local user_bare = username .. "@" .. module.host;
+ for jid in pairs(send_available) do
+ module:send(st.presence({ type = "probe", to = user_bare, from = jid }));
+ end
end
local blocklist_push = st.iq({ type = "set", id = "blocklist-push" })
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 815c2e37..54f0451d 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -91,6 +91,21 @@ 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()
@@ -124,7 +139,6 @@ local function get_broadcaster(username)
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,23 +158,8 @@ local function get_broadcaster(username)
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));
+ module:log("debug", "Sending notification to %s from %s for node %s", jid, user_bare, node);
message.attr.to = jid;
module:send(message);
end
@@ -168,6 +167,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);
@@ -226,6 +240,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;
@@ -240,6 +259,7 @@ end
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 @@ 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:may(node, recipient, "subscribe") then
+ if service:add_subscription(node, recipient, recipient, { presence = true }) then
resend_last_item(recipient, node, service);
end
end
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index c828d17d..34961558 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -391,7 +391,11 @@ function room_mt:handle_kickable(origin, stanza) -- luacheck: ignore 212
end
self:publicise_occupant_status(new_occupant or occupant, x);
if is_last_session then
- module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;});
+ module:fire_event("muc-occupant-left", {
+ room = self;
+ nick = occupant.nick;
+ occupant = occupant;
+ });
end
return true;
end
@@ -868,7 +872,11 @@ function room_mt:clear(x)
end
for occupant in pairs(occupants_updated) do
self:publicise_occupant_status(occupant, x);
- module:fire_event("muc-occupant-left", { room = self; nick = occupant.nick; occupant = occupant;});
+ module:fire_event("muc-occupant-left", {
+ room = self;
+ nick = occupant.nick;
+ occupant = occupant;
+ });
end
end
@@ -1316,7 +1324,11 @@ function room_mt:set_affiliation(actor, jid, affiliation, reason, data)
for occupant, old_role in pairs(occupants_updated) do
self:publicise_occupant_status(occupant, x, nil, actor, reason);
if occupant.role == nil then
- module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;});
+ module:fire_event("muc-occupant-left", {
+ room = self;
+ nick = occupant.nick;
+ occupant = occupant;
+ });
elseif is_semi_anonymous and
(old_role == "moderator" and occupant.role ~= "moderator") or
(old_role ~= "moderator" and occupant.role == "moderator") then -- Has gained or lost moderator status
@@ -1432,7 +1444,11 @@ function room_mt:set_role(actor, occupant_jid, role, reason)
self:save_occupant(occupant);
self:publicise_occupant_status(occupant, x, nil, actor, reason);
if role == nil then
- module:fire_event("muc-occupant-left", {room = self; nick = occupant.nick; occupant = occupant;});
+ module:fire_event("muc-occupant-left", {
+ room = self;
+ nick = occupant.nick;
+ occupant = occupant;
+ });
end
return true;
end