Changeset

6119:6dca425eea15

mod_pubsub_subscription: Don't block pubsub unhandled or bare JID notifications The module was marking every successfully-parsed pubsub notification as handled, which could prevent local users from receiving pubsub notifications. Now it will only eat them if both: - The notification was sent to the host JID - The notification matched a node we consider ourselves subscribed to Notifications to local (i.e. non-host) JIDs will always be let through.
author Matthew Wild <mwild1@gmail.com>
date Sat, 28 Dec 2024 18:45:40 +0000
parents 6118:8338f42d2bc5
children 6120:bd3ff802d883
files mod_pubsub_subscription/mod_pubsub_subscription.lua
diffstat 1 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pubsub_subscription/mod_pubsub_subscription.lua	Sat Dec 28 18:08:17 2024 +0000
+++ b/mod_pubsub_subscription/mod_pubsub_subscription.lua	Sat Dec 28 18:45:40 2024 +0000
@@ -52,12 +52,14 @@
 for _, event_name in ipairs(valid_events) do
 	module:hook("pubsub-event/host/"..event_name, function (event)
 		for _, _, _, _, _, cb in active_subscriptions:iter(event.service, event.node, event.stanza.attr.to, nil, "on_"..event_name) do
+			event.handled = true;
 			pcall(cb, event);
 		end
 	end);
 
 	module:hook("pubsub-event/bare/"..event_name, function (event)
 		for _, _, _, _, _, cb in active_subscriptions:iter(event.service, event.node, event.stanza.attr.to, nil, "on_"..event_name) do
+			event.handled = true;
 			pcall(cb, event);
 		end
 	end);
@@ -132,24 +134,33 @@
 
 function handle_message(context, event)
 	local origin, stanza = event.origin, event.stanza;
-	local ret = nil;
+	local handled = nil;
 	local service = stanza.attr.from;
 	module:log("debug", "Got message/%s: %s", context, stanza:top_tag());
 	for event_container in stanza:childtags("event", xmlns_pubsub_event) do
 		for pubsub_event in event_container:childtags() do
 			module:log("debug", "Got pubsub event %s", pubsub_event:top_tag());
 			local node = pubsub_event.attr.node;
-			module:fire_event("pubsub-event/" .. context .. "/"..pubsub_event.name, {
-					stanza = stanza;
-					origin = origin;
-					event = pubsub_event;
-					service = service;
-					node = node;
-				});
-			ret = true;
+			local event_data = {
+				stanza = stanza;
+				origin = origin;
+				event = pubsub_event;
+				service = service;
+				node = node;
+				handled = false;
+			};
+			module:fire_event("pubsub-event/" .. context .. "/"..pubsub_event.name, event_data);
+			if not handled and event_data.handled then
+				handled = true;
+			end
 		end
 	end
-	return ret;
+	-- If not addressed to the host, let it fall through to normal handling
+	-- (it may be on its way to a local client), otherwise, we'll mark the
+	-- event as handled to suppress an error response if we handled it.
+	if context == "host" and handled then
+		return true;
+	end
 end
 
 module:hook("message/host", function(event)