-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This API endpoint's purpose is to allow affiliation changes to existing subscriptions to a given node.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 /<channel>/subscribers/<node> ////////////////////////////////////////////////////////// | ||
|
||
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); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
for ( var i=0; i<propertyNames.length; i++ ){ | ||
|
||
var key = propertyNames[i]; | ||
This comment has been minimized.
Sorry, something went wrong.
rodrigods
Contributor
|
||
var subscribedChannel = key.split('/', 2)[0]; | ||
var subscribedNode = key.split('/', 2)[1]; | ||
var affiliation = body[key]; | ||
|
||
if ( affiliation != "member" && affiliation != "publisher" && affiliation != "moderator" && affiliation != "outcast" ){ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
continue; | ||
} | ||
|
||
//TODO | ||
//Also filter out from newSubscribedAffiliations those channel jids which aren't actually subscribed to this node. | ||
//Probably by performing a getNodeSubscriptions and comparing the results with the new affiliation information given by the user | ||
|
||
newSubscribedAffiliations.push({ | ||
'jid' : pubsub.channelNodeId(subscribedChannel, subscribedNode), | ||
This comment has been minimized.
Sorry, something went wrong. |
||
'affiliation' : affiliation | ||
}); | ||
} | ||
|
||
} catch (e) { | ||
res.send(400); | ||
} | ||
|
||
api.sendQuery(req, res, pubsub.changeNodeAffiliationsIq(nodeId, newSubscribedAffiliations), function(){ | ||
res.send(200); | ||
}); | ||
|
||
} |
3 comments
on commit 1152658
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, someone code-review and validate my work.
I took a guess, based on https://buddycloud.org/wiki/XMPP_XEP#Retrieve_followers, that the Pub-Sub stanza to change affiliation roles of the followers of a node would be something like this:
<iq type="set" from to>
<pubsub xmlns="http://jabber.org/protocol/pubsub#owner">
<affiliations node="/user/[email protected]/posts">
<affiliation jid="[email protected]" affiliation="moderator"/>
<affiliation jid="[email protected]" affiliation="moderator"/>
<affiliation jid="[email protected]" affiliation="publisher"/>
<affiliation jid="[email protected]" affiliation="member"/>
<affiliation jid="[email protected]" affiliation="member"/>
<affiliation jid="[email protected]" affiliation="outcast"/>
<affiliation jid="[email protected]" affiliation="outcast"/>
<affiliation jid="[email protected]" affiliation="outcast"/>
</affiliations>
</pubsub>
</iq>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, there is only small fixes =)
Please, also test it locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only work if you are the node owner/moderator though, otherwise the nodejs server will fallback to giving you a list of the current user's affiliations (same with subscriptions I believe). The java server does this differently and exposes this data whether you are the owner or not. I raised an issue for this here: buddycloud/deprecated-buddycloud-server#123
you can just do:
for (var key in req.body) {
}