Changeset

10127:cb5e4e07ab11

Merge my line of development->trunk
author João Duarte <jvsDuarte08@gmail.com>
date Fri, 21 Jun 2019 01:16:18 +0100
parents 10058:08c6540f5a65 (diff) 10126:ad640c2e072e (current diff)
children 10128:026815f8d832
files
diffstat 5 files changed, 231 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_blocklist.lua	Thu Jun 20 19:17:47 2019 +0100
+++ b/plugins/mod_blocklist.lua	Fri Jun 21 01:16:18 2019 +0100
@@ -128,6 +128,7 @@
 	-- > 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 @@
 			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 @@
 
 	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 @@
 			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" })
--- a/plugins/mod_pep.lua	Thu Jun 20 19:17:47 2019 +0100
+++ b/plugins/mod_pep.lua	Fri Jun 21 01:16:18 2019 +0100
@@ -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,23 +158,8 @@
 			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 @@
 	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
--- a/plugins/muc/muc.lib.lua	Thu Jun 20 19:17:47 2019 +0100
+++ b/plugins/muc/muc.lib.lua	Fri Jun 21 01:16:18 2019 +0100
@@ -391,7 +391,11 @@
 	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 @@
 	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 @@
 		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 @@
 	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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/scansion/blocking.scs	Fri Jun 21 01:16:18 2019 +0100
@@ -0,0 +1,160 @@
+# XEP-0191: Blocking Command
+
+[Client] Romeo
+	jid: blocker@localhost
+	password: password
+
+[Client] Juliet
+	jid: blockee@localhost
+	password: password
+
+-----
+
+# The parties connect
+Romeo connects
+
+Romeo sends:
+	<presence/>
+
+Romeo receives:
+	<presence from="${Romeo's full JID}"/>
+
+Juliet connects
+
+Juliet sends:
+	<presence/>
+
+Juliet receives:
+	<presence from="${Juliet's full JID}"/>
+
+# They add each other
+Romeo sends:
+	<presence type="subscribe" to="${Juliet's JID}"/>
+
+Romeo receives:
+	<presence from="${Juliet's JID}" to="${Romeo's JID}" type="unavailable"/>
+
+Juliet receives:
+	<presence type="subscribe" to="${Juliet's JID}" from="${Romeo's JID}"/>
+
+Juliet sends:
+	<presence type="subscribed" to="${Romeo's JID}"/>
+
+Romeo receives:
+	<presence from="${Juliet's full JID}" to="${Romeo's JID}">
+	  <delay xmlns="urn:xmpp:delay" stamp="{scansion:any}" from="localhost"/>
+	</presence>
+
+Juliet sends:
+	<presence type="subscribe" to="${Romeo's JID}"/>
+
+Juliet receives:
+	<presence from="${Romeo's JID}" to="${Juliet's JID}" type="unavailable"/>
+
+Romeo receives:
+	<presence type="subscribe" to="${Romeo's JID}" from="${Juliet's JID}"/>
+
+Romeo sends:
+	<presence type="subscribed" to="${Juliet's JID}"/>
+
+Juliet receives:
+	<presence from="${Romeo's full JID}" to="${Juliet's JID}">
+	  <delay xmlns="urn:xmpp:delay" stamp="{scansion:any}" from="localhost"/>
+	</presence>
+
+Romeo receives:
+	<presence from="${Juliet's full JID}" to="${Romeo's JID}">
+	  <delay xmlns="urn:xmpp:delay" stamp="{scansion:any}" from="localhost"/>
+	</presence>
+
+# They can now talk
+Juliet sends:
+	<message type="chat" to="${Romeo's JID}">
+	  <body>ohai</body>
+	</message>
+
+Romeo receives:
+	<message type="chat" to="${Romeo's JID}" from="${Juliet's full JID}">
+	  <body>ohai</body>
+	</message>
+
+# And now to the blockining
+
+Romeo sends:
+	<iq type="set" id="lx2">
+	  <block xmlns="urn:xmpp:blocking">
+	    <item jid="${Juliet's JID}"/>
+	  </block>
+	</iq>
+
+Romeo receives:
+	<iq type="result" id="lx2"/>
+
+Juliet receives:
+	<presence type="unavailable" to="${Juliet's JID}" from="${Romeo's full JID}"/>
+
+# Can"t talk anymore
+Romeo sends:
+	<message type="chat" to="${Juliet's JID}">
+	  <body>hello?</body>
+	</message>
+
+Romeo receives:
+	<message type="error" from="${Juliet's JID}">
+	  <error type="cancel">
+	    <not-acceptable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
+	    <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">You have blocked this JID</text>
+	    <blocked xmlns="urn:xmpp:blocking:errors"/>
+	  </error>
+	</message>
+
+Juliet sends:
+	<message type="chat" to="${Romeo's JID}"/>
+
+Juliet receives:
+	<message type="error" from="${Romeo's JID}">
+	  <error type="cancel">
+	    <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
+	  </error>
+	</message>
+
+Romeo sends:
+	<iq type="set" id="lx3">
+	  <unblock xmlns="urn:xmpp:blocking">
+	    <item jid="${Juliet's JID}"/>
+	  </unblock>
+	</iq>
+
+Juliet receives:
+	<presence to="${Juliet's JID}" from="${Romeo's full JID}">
+	  <delay xmlns="urn:xmpp:delay" stamp="{scansion:any}" from="localhost"/>
+	</presence>
+
+Romeo receives:
+	<iq type="result" id="lx3"/>
+
+# Can talk again
+Romeo sends:
+	<message type="chat" to="${Juliet's JID}">
+	  <body>hello!</body>
+	</message>
+
+Juliet receives:
+	<message type="chat" to="${Juliet's JID}" from="${Romeo's full JID}">
+	  <body>hello!</body>
+	</message>
+
+# Bye
+Juliet disconnects
+
+Juliet sends:
+	<presence type="unavailable"/>
+
+Romeo receives:
+	<presence from="${Juliet's full JID}" to="${Romeo's JID}" type="unavailable"/>
+
+Romeo disconnects
+
+Romeo sends:
+	<presence type="unavailable"/>
+
--- a/util/dependencies.lua	Thu Jun 20 19:17:47 2019 +0100
+++ b/util/dependencies.lua	Fri Jun 21 01:16:18 2019 +0100
@@ -140,7 +140,7 @@
 end
 
 local function log_warnings()
-	if _VERSION > "Lua 5.2" then
+	if _VERSION > "Lua 5.3" then
 		prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION);
 	end
 	local ssl = softreq"ssl";