Mercurial > psgxs
view nodes.js @ 5:d8a98540d749
Reimport nodes methods when loading from file.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 29 Jun 2010 23:29:29 +0200 |
parents | 4c93e76fa371 |
children | 9a6b8b3357c6 |
line wrap: on
line source
/* * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> * * This file is part of PSĜS, a PubSub server written in JavaScript. * * PSĜS is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License. * * PSĜS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. */ require('./iso8601'); var errors = require('./errors'); var config = require('./configuration'); var service_configuration = config.service_configuration; var Configuration = config.Configuration; var makeRandomId = require('./util').makeRandomId; exports.Item = function() { this.content = null; this.date = new Date(); return this; }; exports.Node = function(params) { this.items = {}; if (config.enabled('subscribe')) this.subscribers = {}; this.owner = []; if (params && params['pubsub#creator']) this.owner.push(params['pubsub#creator']); if (config.enabled('publisher-affiliation')) this.publisher = []; if (config.enabled('publish-only-affiliation')) this.publishOnly = []; if (config.enabled('member-affiliation')) this.member = []; if (config.enabled('outcast-affiliation')) this.outcast = []; if (config.enabled('meta-data')) this.metadata = new Configuration(service_configuration.node_metadata, params); if (config.enabled('config-node')) this.configuration = new Configuration(service_configuration.node_config, params); if (config.enabled('subscription-options')) this.subsConfig = new Configuration(service_configuration.subscribe_options, params); return this; }; exports.Node.prototype = { setItem: function(name, content) { if (typeof content == 'undefined') { if (this.items[name]) { delete this.items[name]; return errors.success; } return 42; //XXX } if (!this.items[name]) this.items[name] = new exports.Item(); this.items[name].content = content; return errors.success; }, setSubscriber: function(jid, type, subid, params) { if (type == 'none') { delete this.subscribers[jid]; this.metadata['pubsub#num_subscribers']--; return errors.success; } if (!subid) subid = makeRandomId(); this.subscribers[jid] = { type: type, subid: subid, options: new Configuration(service_configuration.subscribe_options, params), } this.metadata['pubsub#num_subscribers']++; return subid; }, };