Mercurial > psgxs
changeset 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 | b98e545a94f7 |
files | forms.js modules.js modules/mod_configure.js modules/mod_disco.js modules/mod_publish_message.js modules/mod_retrieve.js modules/mod_subscribe.js psgxs.js |
diffstat | 8 files changed, 54 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/forms.js +++ b/forms.js @@ -62,7 +62,9 @@ exports.build = function(type, desc, con if (desc[i].label) fieldAttr.label = desc[i].label; } - x.c('field', fieldAttr); + + var field = new Element('field', fieldAttr); + x.cnode(field); if (labels && (desc[i].type == 'list-multi' || @@ -71,22 +73,22 @@ exports.build = function(type, desc, con var optAttr = {}; if (desc[i].options[j].label) optAttr.label = desc[i].options[j].label; - x.c('option', optAttr).c('value').t(j).up().up(); + field.c('option', optAttr).c('value').t(j).up().up(); } } if (i == 'FORM_TYPE') - x.c('value').t(desc[i].value).up(); + field.c('value').t(desc[i].value).up(); else if (typeof content[i] != 'undefined') { var md = content[i]; if (desc[i].type == 'jid-multi' || desc[i].type == 'list-multi' || desc[i].type == 'text-multi') { for (var j=0; j<md.length; j++) - x.c('value') + field.c('value') .t(md[j].toString()).up(); } else - x.c('value').t(md.toString()).up(); + field.c('value').t(md.toString()).up(); } x.up();
--- a/modules.js +++ b/modules.js @@ -28,8 +28,10 @@ var regex = /^mod_.*\.js/; var Script = process.binding('evals').Script; var fdsq = require('./fdsq'); + var sandbox = { process: process, + console: console, config: require('./configuration'), Element: require('ltx').Element, uuid: require('uuid'),
--- a/modules/mod_configure.js +++ b/modules/mod_configure.js @@ -44,10 +44,9 @@ exports.getConfigure = { return makeError(response, 42); // FIXME response.c('pubsub', {xmlns: NS.PUBSUB_OWNER}) - .c('configure', {node: nodeID}); + .c('configure', {node: nodeID}) + .cnode(forms.build('form', 'node_config', conf, true)); - var form = forms.build('form', 'node_config', conf, true); - response.cnode(form); return response; }
--- 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;
--- a/modules/mod_publish_message.js +++ b/modules/mod_publish_message.js @@ -50,11 +50,11 @@ exports.publishMessage = { var now = new Date(); - var item = xmpp.stanza('item', {xmlns: NS.PUBSUB, id: itemID}); + var item = new Element('item', {xmlns: NS.PUBSUB, id: itemID}); item.c('entry', {xmlns: NS.ATOM}); if (stanza.getChild('subject')) item.c('title').t(stanza.getChild('subject')).up(); - item.c('summary').t(request.getText()).up(); + item.c('content', {type: 'text'}).t(request.getText()).up(); item.c('id').t(itemID).up(); item.c('published').t(now.toString()).up(); item.c('updated').t(now.toString()).up(); @@ -75,9 +75,10 @@ exports.publishMessage = { return makeError(response, r); } + console.log(item); var content = item.getChild(); - subscribers = storage.setItem(nodeID, itemID, content); + var subscribers = storage.setItem(nodeID, itemID, content); if (typeof subscribers == 'number') return makeError(response, subscribers);
--- a/modules/mod_retrieve.js +++ b/modules/mod_retrieve.js @@ -82,7 +82,7 @@ exports.retrieveItems = { child: 'pubsub', ns: NS.PUBSUB, child2: 'items', - func: function(response, stanza, request, to) { + func: function(response, attrs, request, to) { if (!config.enabled('retrieve-items')) return makeError(response, errors.sub.default_options.node_configuration_not_supported.n); @@ -100,21 +100,22 @@ exports.retrieveItems = { } var item = []; - for (var i=0; i<request.tags.length; i++) { - var j = request.tags[i]; + for (var i=0; i<request.children.length; i++) { + var j = request.children[i]; if (j.name == 'item' && j.attr['id'] && j.attr['id'] != '') item.push(j.attr['id']); } - response.c('pubsub', {xmlns: NS.PUBSUB}); - var max_items = request.getAttribute('max_items'); if (max_items) max_items = Number (max_items); + var items = new Element('items', {node: nodeID}); + + response.c('pubsub', {xmlns: NS.PUBSUB}) + .cnode(items); + if (item.length) { - response.c('items', {node: nodeID}); - for (var i=0; i<item.length; i++) { var j = storage.getItem(nodeID, item[i]); if (typeof j == 'number') @@ -122,12 +123,10 @@ exports.retrieveItems = { if (j == errors.success) continue; - response.c('item', {id: item[i]}) + items.c('item', {id: item[i]}) .cnode(j).up().up(); } } else { - response.c('items', {node: nodeID}); - var j; if (max_items) j = storage.getLastItem(nodeID, max_items); @@ -138,7 +137,7 @@ exports.retrieveItems = { var k = 0; for (var i in j) - response.c('item', {id: i}).t(j[i].content).up(); + items.c('item', {id: i}).t(j[i].content).up(); } return response;
--- a/modules/mod_subscribe.js +++ b/modules/mod_subscribe.js @@ -25,7 +25,7 @@ exports.subscribe = { child: 'pubsub', ns: NS.PUBSUB, child2: 'subscribe', - func: function(response, stanza, request, to) { + func: function(response, attrs, request, to) { if (!config.enabled('subscribe')) return makeError(response, errors.sub.subscribe.not_supported.n);
--- a/psgxs.js +++ b/psgxs.js @@ -133,7 +133,7 @@ function onIq(stanza) { if (module.number && (module.number != k)) continue; - send.response = module.func(response, stanza, payload, to, from); + send.response = module.func(response, payload.attrs, child, to, from); if (send.response) { response = send.response; send.good = true;