javascript - Not being available to change user installation in Parse Cloud Code -


i trying add new channels parse installation of other users using parse cloud. parse cloud code:

  parse.cloud.define("subscribetochannel", function(request, response) {   var channelname = request.params.channel;   var ids = request.params.ids;//this array of ids change   var _ = require("underscore");   _.each(ids, function(id) {   // create pointer user based on object id     var user = new parse.user();     user.id = id;     // need master key update installations     parse.cloud.usemasterkey();      // user might have more 1 installation     var query = new parse.query(parse.installation);     query.equalto("user", user); // match installations pointer user     query.find({       success: function(installations){     (var = 0; < installations.length; i++){       // add channel installations user       installations[i].addunique("channels", channelname);     }     // save installations     parse.object.saveall(installations, {       success: function(installations) {       },       error: function(error) {         // error occurred while saving 1 of objects.         console.error(error);       }     });       },       error: function(error) {     console.error(error);       }     });   }); 

and how set first installation each user:

parseinstallation inst = parseinstallation.getcurrentinstallation(); inst.put("user", parseuser.getcurrentuser()); 

the array of ids send jsonarray contains list of string ids. jsonarray gets , iterate correctly. no matter how many times have tried, seems not work. thanks!

my error wasn't saving channel in correct way. after long talking dev team in parse able make happen. here code:

parse.cloud.define("subscribetochannel", function(request, response) { var channelname = request.params.channel; //channel user subscribed var ids = request.params.ids; //id of users var completed = true; var size = 0; var pased = 0; var loops = 0; var idstrings = ""; var _ = require("underscore"); if (!channelname) { response.error("missing parameter: channel"); return; } if (!ids) { response.error("missing parameter: ids"); return; } var query = new parse.query(parse.installation); var user = new parse.user(); var changedobjects = []; var pointerarray = []; _.each(ids, function(id){ pointerarray.push({"__type":"pointer","classname":"_user","objectid":id}); });  // need master key update installations parse.cloud.usemasterkey(); query.containedin("user",pointerarray); query.find({ success: function(installations){ (var = 0; < installations.length; i++){ // add channel installations user installations[i].addunique("channels", channelname); //add channel installation changedobjects.push(installations[i]); //add installation saved later on! }  //saving installations parse.object.saveall(changedobjects, {  success: function(installations) { response.success(); }, error: function(error) { // error occurred while saving 1 of objects. response.error(error); } }); }, error: function(error) { response.error(error); } }); }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -