comparison modules/mod_publish_message.js @ 35:6697f394301f

Replace util with fdsq to work around a stupid bug.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 10 Nov 2010 01:30:03 +0100
parents dcf1f09f8cee
children bc717575e66a
comparison
equal deleted inserted replaced
34:dcf1f09f8cee 35:6697f394301f
1 var config = require('../configuration'); 1 var config = require('../configuration');
2 var storage = require('../storage'); 2 var storage = require('../storage');
3 var notifs = require('../notifs'); 3 var notifs = require('../notifs');
4 var errors = require('../errors'); 4 var errors = require('../errors');
5 var utils = require('../util'); 5 var makeError = errors.makeError;
6 var toBareJID = utils.toBareJID; 6 var fdsq = require('../fdsq');
7 var toBareJID = fdsq.toBareJID;
7 var NS = require('../namespaces'); 8 var NS = require('../namespaces');
8 var xmpp = require('xmpp'); 9 var xmpp = require('xmpp');
9 10
10 exports.publish = { 11 exports.publishMessage = {
11 stanza: 'message', 12 stanza: 'message',
12 child: 'body', 13 child: 'body',
13 func: function(response, stanza, request, to, from) { 14 func: function(response, stanza, request, to, from) {
14 if (!config.enabled('publish')) 15 if (!config.enabled('publish'))
15 return makeError(response, errors.pub.publish.item_publication_not_supported.n); 16 return makeError(response, errors.pub.publish.item_publication_not_supported.n);
16 17
17 var nodeID = utils.toResource(from); 18 var nodeID = fdsq.toResource(from);
18 console.log(require('sys').inspect(nodeID));
19 if (!nodeID || nodeID == '') 19 if (!nodeID || nodeID == '')
20 return makeError(response, errors.nodeid_required.n); 20 return makeError(response, errors.nodeid_required.n);
21 21
22 var autocreate = false; 22 var autocreate = false;
23 if (!storage.existsNode(nodeID)) { 23 if (!storage.existsNode(nodeID)) {
33 if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only') 33 if (!autocreate && affil != 'super-owner' && affil != 'owner' && affil != 'publisher' && affil != 'publish-only')
34 return makeError(response, errors.forbidden.n); 34 return makeError(response, errors.forbidden.n);
35 35
36 if (!config.enabled('item-ids')) 36 if (!config.enabled('item-ids'))
37 return makeError(response, errors.itemid_required.n); 37 return makeError(response, errors.itemid_required.n);
38 var itemID = utils.makeRandomId(); 38 var itemID = fdsq.makeRandomId();
39 39
40 var now = new Date(); 40 var now = new Date();
41 41
42 var item = xmpp.stanza('item', {xmlns: NS.PUBSUB, id: itemID}); 42 var item = xmpp.stanza('item', {xmlns: NS.PUBSUB, id: itemID});
43 item.c('entry', {xmlns: NS.ATOM}); 43 item.c('entry', {xmlns: NS.ATOM});
45 item.c('title').t(stanza.getChild('subject')).up(); 45 item.c('title').t(stanza.getChild('subject')).up();
46 item.c('summary').t(request.getText()).up(); 46 item.c('summary').t(request.getText()).up();
47 item.c('id').t(itemID).up(); 47 item.c('id').t(itemID).up();
48 item.c('published').t(now.toString()).up(); 48 item.c('published').t(now.toString()).up();
49 item.c('updated').t(now.toString()).up(); 49 item.c('updated').t(now.toString()).up();
50 console.log(require('sys').inspect(item, false, null));
51 50
52 if (!config.enabled('persistent-items')) { 51 if (!config.enabled('persistent-items')) {
53 var notifications = storage.purgeNode(nodeID); 52 var notifications = storage.purgeNode(nodeID);
54 if (typeof notifications == 'number') 53 if (typeof notifications == 'number')
55 return makeError(response, r); 54 return makeError(response, r);