diff modules/mod_disco.js @ 42:07ca0263a53f

Add an option to hide non-accessible nodes.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 26 Feb 2011 17:39:49 +0100
parents bc717575e66a
children 023f767662d3
line wrap: on
line diff
--- a/modules/mod_disco.js
+++ b/modules/mod_disco.js
@@ -54,7 +54,7 @@ exports.disco_items = {
 	type: 'get',
 	child: 'query',
 	ns: NS.DISCO_ITEMS,
-	func: function(response, stanza, request) {
+	func: function(response, stanza, request, to) {
 		var children;
 		var nodeID = request.getAttribute('node');
 		if (nodeID && nodeID != '') {
@@ -84,19 +84,29 @@ exports.disco_items = {
 				return makeError(response, children);
 		}
 
-		for (var i in children) {
+		for (var nodeID in children) {
 			var attr = {jid: config.jid};
-			if (children[i] == 'node') {
+			if (children[nodeID] == 'node') {
 				if (config.enabled('meta-data')) {
-					var metadata = storage.getMetadata(i);
+					var metadata = storage.getMetadata(nodeID);
 					if (metadata['pubsub#title'])
 						attr.name = metadata['pubsub#title'];
+
+					if (config.hideNonAccessibleNodes) {
+						var configuration = storage.getConfiguration(nodeID);
+						if (configuration['pubsub#access_model'] == 'whitelist') {
+							var affils = storage.getAffiliationsFromNodeID(nodeID);
+							var affil = affils[toBareJID(to)];
+							if (!affil || affil == 'outcast')
+								continue;
+						}
+					}
 				}
-				attr.node = i;
+				attr.node = nodeID;
 
 			// SECTION 5.5: Discover Items for a Node
 			} else
-				attr.name = i;
+				attr.name = nodeID;
 
 			response.c('item', attr).up();
 		}