From 11526583508ba5ea72320c884f6090831bcbbbe2 Mon Sep 17 00:00:00 2001 From: Guilherme Santos Date: Tue, 16 Jul 2013 17:38:37 -0300 Subject: [PATCH] POST /:channel/subscribers/:node endpoint created This API endpoint's purpose is to allow affiliation changes to existing subscriptions to a given node. --- src/subscriptions.js | 51 ++++++++++++++++++++++++++++++++++++++++++++ src/util/pubsub.js | 17 +++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/src/subscriptions.js b/src/subscriptions.js index f2f9330..c332269 100644 --- a/src/subscriptions.js +++ b/src/subscriptions.js @@ -39,6 +39,9 @@ exports.setup = function(app) { app.get('/:channel/subscribers/:node', session.provider, getNodeSubscriptions); + app.post('/:channel/subscribers/:node', + session.provider, + changeNodeSubscriptions); }; //// GET /subscribed /////////////////////////////////////////////////////////// @@ -171,3 +174,51 @@ function requestNodeAffiliations(req, res, channel, node, callback) { var iq = pubsub.nodeAffiliationsIq(nodeId); api.sendQuery(req, res, iq, callback); } + +//// POST //subscribers/ ////////////////////////////////////////////////////////// + +function changeNodeSubscriptions(req, res) { + if (!req.user) { + api.sendUnauthorized(res); + return; + } + + var channel = req.params.channel; + var node = req.params.node; + + var nodeId = pubsub.channelNodeId(channel, node); + var newSubscribedAffiliations = []; + + try { + + var propertyNames = Object.getOwnPropertyNames(req.body); + for ( var i=0; i IQ with multiple tags, + * each composed by a jid of a subscribing channel and its new type of affiliation. + * The parameter must be an array of entries in the format: + * {'jid' : 'jid_val', 'affiliation' : 'affiliation_type'} + */ +exports.changeNodeAffiliationsIq = function(nodeId, subscribedJIDAndAffiliation) { + var iqBody = iq({type : 'set'}, exports.ownerNS). + c('affiliations', {node: nodeId}); + + for ( var i=0; i IQ, which subscribes to a node. */