Add to another user array Parse Android -


in parse have column in user table known 'friends' array. current user trying add user's friends array.

i have tried:

//buddy = string of other person's username //to add current user's array (this working) userlist.user.addunique("friends", buddy); userlist.user.saveeventually();      //this add user's array (not working)     parsequery<parseuser> query = parseuser.getquery();     query.whereequalto("username", buddy);     query.findinbackground(new findcallback<parseuser>() {         public void done(list<parseuser> objects, parseexception e) {             if (e == null) {                 // query successful.                 (parseobject friend : objects) {                     friend.addunique("friends",userlist.user.getusername());                     friend.saveeventually();                 }             } else {                 // went wrong.                 log.d("username", "error: " + e.getmessage());             }         }     }); 

write method in java passes data cloud, , calls function on cloud name:

// passes cloud stored on hashmap hashmap<string, object> params = new hashmap<string, object>(); // user's name add buddy params.put("username", username);     // buddy's name pass cloud     params.put("buddy", buddy); parsecloud.callfunctioninbackground("addbuddytofriendslist", params, new functioncallback<string>(){     public void done(string result, parseexception e){     // e==null means no errors in running function        if(e==null){           system.out.println(result);        }else{           system.out.println(e.getmessage());        }     } }); 

ok, , let's write function used in cloud (assuming know how deploy functions on cloud):

[edited]

parse.cloud.define("addbuddytofriendslist", function (request, response){ parse.cloud.usemasterkey(); var query = new parse.query(parse.user); query.equalto("username", request.params.username);     query.find({     success: function(user) {         // query.find returns array.....                     user[0].addunique("friends", request.params.buddy);         user[0].save(null, {            success: function(success){               response.success();            },             error: function (error){                response.error(error);            }         });         },          error: function(object, error) {}     }); }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -