diff modules/mod_disco.js @ 57:addbf6bbfaa8

Various fixes for the migration to ltx.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Sep 2011 23:45:00 +0200
parents 99bd1d1ac071
children
line wrap: on
line diff
--- a/modules/mod_disco.js
+++ b/modules/mod_disco.js
@@ -28,7 +28,7 @@ exports.disco_info = {
 		var nodeID = request.getAttribute('node');
 
 		// SECTION 5.3: Discover Node Information
-		if (nodeID && nodeID != '') {
+		if (nodeID) {
 			if (!storage.existsNode(nodeID))
 				return makeError(response, errors.node_does_not_exist.n);
 
@@ -40,15 +40,17 @@ exports.disco_info = {
 			if (conf['pubsub#node_type'])
 				type = conf['pubsub#node_type'];
 
-			response.c('query', {xmlns: NS.DISCO_INFO, node: nodeID})
+			var query = new Element('query', {xmlns: NS.DISCO_INFO, node: nodeID})
 				.c('identity', {category: 'pubsub', type: type}).up()
 				.c('feature', {'var': NS.PUBSUB}).up();
 
+			response.cnode(query);
+
 			// SECTION 5.4
 			if (config.enabled('meta-data')) {
 				var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true);
 				if (x)
-					response.cnode(x);
+					query.cnode(x);
 			}
 
 		// SECTION 5.1: Discover Features
@@ -80,33 +82,37 @@ exports.disco_items = {
 	func: function(response, stanza, request, to) {
 		var children;
 		var nodeID = request.getAttribute('node');
-		if (nodeID && nodeID != '') {
+		if (nodeID && nodeID !== '') {
 			if (nodeID == NS.COMMANDS) {
 				// XEP-0050: Ad-Hoc Commands
 
-				response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID})
+				var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID})
 					.c('item', {jid: config.jid, node: 'ping', name: 'Ping'}).up()
 					.c('item', {jid: config.jid, node: 'reload', name: 'Reload'}).up();
 
+				response.cnode(query);
+
 				return response;
-			} else {
-				if (!storage.existsNode(nodeID))
-					return makeError(response, errors.node_does_not_exist.n);
-
-				response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID});
+			}
 
-				children = storage.getChildren(nodeID);
-				if (typeof children == 'number')
-					return makeError(response, children);
-			}
-		} else {
-			response.c('query', {xmlns: NS.DISCO_ITEMS});
+			if (!storage.existsNode(nodeID))
+				return makeError(response, errors.node_does_not_exist.n);
 
-			children = storage.getChildren();
+			var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID});
+			response.cnode(query);
+
+			children = storage.getChildren(nodeID);
 			if (typeof children == 'number')
 				return makeError(response, children);
 		}
 
+		var query = new Element('query', {xmlns: NS.DISCO_ITEMS});
+		response.cnode(query);
+
+		children = storage.getChildren();
+		if (typeof children == 'number')
+			return makeError(response, children);
+
 		for (var nodeID in children) {
 			var attr = {jid: config.jid};
 			if (children[nodeID] == 'node') {
@@ -115,6 +121,9 @@ exports.disco_items = {
 					if (metadata['pubsub#title'])
 						attr.name = metadata['pubsub#title'];
 
+					if (metadata['pubsub#creator'])
+						attr.creator = metadata['pubsub#creator'];
+
 					if (config.hideNonAccessibleNodes) {
 						var configuration = storage.getConfiguration(nodeID);
 						if (configuration['pubsub#access_model'] == 'whitelist') {
@@ -131,7 +140,7 @@ exports.disco_items = {
 			} else
 				attr.name = nodeID;
 
-			response.c('item', attr).up();
+			query.c('item', attr).up();
 		}
 
 		return response;