Changeset

7780:dbd202e7c587

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 10 Dec 2016 02:55:38 +0100
parents 7768:57d0f2d3d5c5 (current diff) 7779:b1f80447a2b1 (diff)
children 7786:b62353e6a8e5
files util/dependencies.lua
diffstat 5 files changed, 51 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Dec 05 23:03:09 2016 +0100
+++ b/.hgignore	Sat Dec 10 02:55:38 2016 +0100
@@ -1,5 +1,6 @@
 syntax: glob
 .hgignore
+.luacheckcache
 data
 local
 www_files
--- a/core/rostermanager.lua	Mon Dec 05 23:03:09 2016 +0100
+++ b/core/rostermanager.lua	Sat Dec 10 02:55:38 2016 +0100
@@ -234,6 +234,18 @@
 	local item = roster[jid];
 	return item and (item.subscription == "from" or item.subscription == "both"), err;
 end
+local function is_user_subscribed(username, host, jid)
+	do
+		local selfjid = username.."@"..host;
+		local user_subscription = _get_online_roster_subscription(selfjid, jid);
+		if user_subscription then return (user_subscription == "both" or user_subscription == "to"); end
+		local contact_subscription = _get_online_roster_subscription(jid, selfjid);
+		if contact_subscription then return (contact_subscription == "both" or contact_subscription == "from"); end
+	end
+	local roster, err = load_roster(username, host);
+	local item = roster[jid];
+	return item and (item.subscription == "to" or item.subscription == "both"), err;
+end
 
 function is_contact_pending_in(username, host, jid)
 	local roster = load_roster(username, host);
@@ -350,6 +362,7 @@
 	process_inbound_subscription_cancellation = process_inbound_subscription_cancellation;
 	process_inbound_unsubscribe = process_inbound_unsubscribe;
 	is_contact_subscribed = is_contact_subscribed;
+	is_user_subscribed = is_user_subscribed;
 	is_contact_pending_in = is_contact_pending_in;
 	set_contact_pending_in = set_contact_pending_in;
 	is_contact_pending_out = is_contact_pending_out;
--- a/plugins/mod_blocklist.lua	Mon Dec 05 23:03:09 2016 +0100
+++ b/plugins/mod_blocklist.lua	Sat Dec 10 02:55:38 2016 +0100
@@ -54,26 +54,21 @@
 
 -- Migrates from the old mod_privacy storage
 local function migrate_privacy_list(username)
-	local migrated_data = { [false] = "not empty" };
 	local legacy_data = module:open_store("privacy"):get(username);
-	if legacy_data and legacy_data.lists and legacy_data.default then
-		legacy_data = legacy_data.lists[legacy_data.default];
-		legacy_data = legacy_data and legacy_data.items;
-	else
-		return migrated_data;
-	end
-	if legacy_data then
-		module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
-		local item, jid;
-		for i = 1, #legacy_data do
-			item = legacy_data[i];
-			if item.type == "jid" and item.action == "deny" then
-				jid = jid_prep(item.value);
-				if not jid then
-					module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value));
-				else
-					migrated_data[jid] = true;
-				end
+	if not legacy_data or not legacy_data.lists or not legacy_data.default then return; end
+	local default_list = legacy_data.lists[legacy_data.default];
+	if not default_list or not default_list.items then return; end
+
+	local migrated_data = { [false] = { created = os.time(); migrated = "privacy" }};
+
+	module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
+	for _, item in ipairs(default_list.items) do
+		if item.type == "jid" and item.action == "deny" then
+			local jid = jid_prep(item.value);
+			if not jid then
+				module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value));
+			else
+				migrated_data[jid] = true;
 			end
 		end
 	end
@@ -82,10 +77,7 @@
 end
 
 local function get_blocklist(username)
-	local blocklist = cache[username];
-	if not blocklist then
-		blocklist = cache2:get(username);
-	end
+	local blocklist = cache2:get(username);
 	if not blocklist then
 		if not user_exists(username, module.host) then
 			return null_blocklist;
@@ -94,6 +86,9 @@
 		if not blocklist then
 			blocklist = migrate_privacy_list(username);
 		end
+		if not blocklist then
+			blocklist = { [false] = { created = os.time(); }; };
+		end
 		cache2:set(username, blocklist);
 	end
 	cache[username] = blocklist;
@@ -104,7 +99,7 @@
 	local origin, stanza = event.origin, event.stanza;
 	local username = origin.username;
 	local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" });
-	local blocklist = get_blocklist(username);
+	local blocklist = cache[username] or get_blocklist(username);
 	for jid in pairs(blocklist) do
 		if jid then
 			reply:tag("item", { jid = jid }):up();
@@ -158,20 +153,25 @@
 		return true;
 	end
 
-	local blocklist = get_blocklist(username);
+	local blocklist = cache[username] or get_blocklist(username);
 
-	local new_blocklist = {};
+	local new_blocklist = {
+		-- We set the [false] key to someting as a signal not to migrate privacy lists
+		[false] = blocklist[false] or { created = os.time(); };
+	};
+	if type(blocklist[false]) == "table" then
+		new_blocklist[false].modified = os.time();
+	end
 
 	if is_blocking or next(new) then
 		for jid in pairs(blocklist) do
-			new_blocklist[jid] = true;
+			if jid then new_blocklist[jid] = true; end
 		end
 		for jid in pairs(new) do
 			new_blocklist[jid] = is_blocking;
 		end
 		-- else empty the blocklist
 	end
-	new_blocklist[false] = "not empty"; -- In order to avoid doing the migration thing twice
 
 	local ok, err = set_blocklist(username, new_blocklist);
 	if ok then
--- a/plugins/mod_carbons.lua	Mon Dec 05 23:03:09 2016 +0100
+++ b/plugins/mod_carbons.lua	Sat Dec 10 02:55:38 2016 +0100
@@ -24,21 +24,23 @@
 	local origin, stanza = event.origin, event.stanza;
 	local orig_type = stanza.attr.type or "normal";
 	local orig_from = stanza.attr.from;
+	local bare_from = jid_bare(orig_from);
 	local orig_to = stanza.attr.to;
-	
+	local bare_to = jid_bare(orig_to);
+
 	if not(orig_type == "chat" or (orig_type == "normal" and stanza:get_child("body"))) then
 		return -- Only chat type messages
 	end
 
 	-- Stanza sent by a local client
-	local bare_jid = jid_bare(orig_from);
+	local bare_jid = bare_from; -- JID of the local user
 	local target_session = origin;
 	local top_priority = false;
-	local user_sessions = bare_sessions[bare_jid];
+	local user_sessions = bare_sessions[bare_from];
 
 	-- Stanza about to be delivered to a local client
 	if not c2s then
-		bare_jid = jid_bare(orig_to);
+		bare_jid = bare_to;
 		target_session = full_sessions[orig_to];
 		user_sessions = bare_sessions[bare_jid];
 		if not target_session and user_sessions then
--- a/plugins/mod_presence.lua	Mon Dec 05 23:03:09 2016 +0100
+++ b/plugins/mod_presence.lua	Sat Dec 10 02:55:38 2016 +0100
@@ -178,7 +178,9 @@
 		end
 		core_post_stanza(origin, stanza);
 		send_presence_of_available_resources(node, host, to_bare, origin);
-		core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare }));
+		if rostermanager.is_user_subscribed(node, host, to_bare) then
+			core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare }));
+		end
 	elseif stanza.attr.type == "unsubscribed" then
 		-- 1. send unavailable
 		-- 2. route stanza