comparison 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
comparison
equal deleted inserted replaced
56:99bd1d1ac071 57:addbf6bbfaa8
26 ns: NS.DISCO_INFO, 26 ns: NS.DISCO_INFO,
27 func: function(response, stanza, request) { 27 func: function(response, stanza, request) {
28 var nodeID = request.getAttribute('node'); 28 var nodeID = request.getAttribute('node');
29 29
30 // SECTION 5.3: Discover Node Information 30 // SECTION 5.3: Discover Node Information
31 if (nodeID && nodeID != '') { 31 if (nodeID) {
32 if (!storage.existsNode(nodeID)) 32 if (!storage.existsNode(nodeID))
33 return makeError(response, errors.node_does_not_exist.n); 33 return makeError(response, errors.node_does_not_exist.n);
34 34
35 var conf = storage.getConfiguration(nodeID); 35 var conf = storage.getConfiguration(nodeID);
36 if (typeof conf == 'number') 36 if (typeof conf == 'number')
38 38
39 var type = 'leaf' 39 var type = 'leaf'
40 if (conf['pubsub#node_type']) 40 if (conf['pubsub#node_type'])
41 type = conf['pubsub#node_type']; 41 type = conf['pubsub#node_type'];
42 42
43 response.c('query', {xmlns: NS.DISCO_INFO, node: nodeID}) 43 var query = new Element('query', {xmlns: NS.DISCO_INFO, node: nodeID})
44 .c('identity', {category: 'pubsub', type: type}).up() 44 .c('identity', {category: 'pubsub', type: type}).up()
45 .c('feature', {'var': NS.PUBSUB}).up(); 45 .c('feature', {'var': NS.PUBSUB}).up();
46
47 response.cnode(query);
46 48
47 // SECTION 5.4 49 // SECTION 5.4
48 if (config.enabled('meta-data')) { 50 if (config.enabled('meta-data')) {
49 var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true); 51 var x = forms.build('result', 'node_metadata', storage.getMetadata(nodeID), true);
50 if (x) 52 if (x)
51 response.cnode(x); 53 query.cnode(x);
52 } 54 }
53 55
54 // SECTION 5.1: Discover Features 56 // SECTION 5.1: Discover Features
55 } else { 57 } else {
56 var query = new Element('query', {xmlns: NS.DISCO_INFO}) 58 var query = new Element('query', {xmlns: NS.DISCO_INFO})
78 child: 'query', 80 child: 'query',
79 ns: NS.DISCO_ITEMS, 81 ns: NS.DISCO_ITEMS,
80 func: function(response, stanza, request, to) { 82 func: function(response, stanza, request, to) {
81 var children; 83 var children;
82 var nodeID = request.getAttribute('node'); 84 var nodeID = request.getAttribute('node');
83 if (nodeID && nodeID != '') { 85 if (nodeID && nodeID !== '') {
84 if (nodeID == NS.COMMANDS) { 86 if (nodeID == NS.COMMANDS) {
85 // XEP-0050: Ad-Hoc Commands 87 // XEP-0050: Ad-Hoc Commands
86 88
87 response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}) 89 var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID})
88 .c('item', {jid: config.jid, node: 'ping', name: 'Ping'}).up() 90 .c('item', {jid: config.jid, node: 'ping', name: 'Ping'}).up()
89 .c('item', {jid: config.jid, node: 'reload', name: 'Reload'}).up(); 91 .c('item', {jid: config.jid, node: 'reload', name: 'Reload'}).up();
90 92
93 response.cnode(query);
94
91 return response; 95 return response;
92 } else { 96 }
93 if (!storage.existsNode(nodeID))
94 return makeError(response, errors.node_does_not_exist.n);
95 97
96 response.c('query', {xmlns: NS.DISCO_ITEMS, node: nodeID}); 98 if (!storage.existsNode(nodeID))
99 return makeError(response, errors.node_does_not_exist.n);
97 100
98 children = storage.getChildren(nodeID); 101 var query = new Element('query', {xmlns: NS.DISCO_ITEMS, node: nodeID});
99 if (typeof children == 'number') 102 response.cnode(query);
100 return makeError(response, children);
101 }
102 } else {
103 response.c('query', {xmlns: NS.DISCO_ITEMS});
104 103
105 children = storage.getChildren(); 104 children = storage.getChildren(nodeID);
106 if (typeof children == 'number') 105 if (typeof children == 'number')
107 return makeError(response, children); 106 return makeError(response, children);
108 } 107 }
108
109 var query = new Element('query', {xmlns: NS.DISCO_ITEMS});
110 response.cnode(query);
111
112 children = storage.getChildren();
113 if (typeof children == 'number')
114 return makeError(response, children);
109 115
110 for (var nodeID in children) { 116 for (var nodeID in children) {
111 var attr = {jid: config.jid}; 117 var attr = {jid: config.jid};
112 if (children[nodeID] == 'node') { 118 if (children[nodeID] == 'node') {
113 if (config.enabled('meta-data')) { 119 if (config.enabled('meta-data')) {
114 var metadata = storage.getMetadata(nodeID); 120 var metadata = storage.getMetadata(nodeID);
115 if (metadata['pubsub#title']) 121 if (metadata['pubsub#title'])
116 attr.name = metadata['pubsub#title']; 122 attr.name = metadata['pubsub#title'];
123
124 if (metadata['pubsub#creator'])
125 attr.creator = metadata['pubsub#creator'];
117 126
118 if (config.hideNonAccessibleNodes) { 127 if (config.hideNonAccessibleNodes) {
119 var configuration = storage.getConfiguration(nodeID); 128 var configuration = storage.getConfiguration(nodeID);
120 if (configuration['pubsub#access_model'] == 'whitelist') { 129 if (configuration['pubsub#access_model'] == 'whitelist') {
121 var affils = storage.getAffiliationsFromNodeID(nodeID); 130 var affils = storage.getAffiliationsFromNodeID(nodeID);
129 138
130 // SECTION 5.5: Discover Items for a Node 139 // SECTION 5.5: Discover Items for a Node
131 } else 140 } else
132 attr.name = nodeID; 141 attr.name = nodeID;
133 142
134 response.c('item', attr).up(); 143 query.c('item', attr).up();
135 } 144 }
136 145
137 return response; 146 return response;
138 } 147 }
139 } 148 }