5

I want to send a push notification from parse cloud code to a specific user. So i have created a user section in installation class of my parse table and i save the user object id there so i can target the user by id and send push from cloud code. https://www.dropbox.com/s/dvedyza4bz3z00j/userObjec.PNG?dl=0

From parse.com it is very simple to do, i did it like this with condition https://www.dropbox.com/s/1mb3pb2izb0jlj9/pushs.PNG?dl=0

But what i want to do is to send a push notification when a user adds new object in the class my class is "Ticket".

This class has ACL enabled. What i want to do is very simple send push to the user which created the object through cloud code

Here is my cloud code

  Parse.Cloud.afterSave("Ticket", function(request) {
  var pushQuery = new Parse.Query(Parse.Installation);

  Parse.Push.send({
        where: pushQuery,
        data: {
            alert: "New Ticket Added",
            sound: "default"
              }
        },{
        success: function(){
           response.success('true');
        },
        error: function (error) {
           response.error(error);
        }
      });
});

This code sends push to all users.

Please help

1

2 Answers 2

10

This can be a solution:

Parse.Cloud.afterSave( "Ticket", function(request) {

                 //Get value from Ticket Object
                  var username = request.object.get("username");

                  //Set push query
                  var pushQuery = new Parse.Query(Parse.Installation);
                  pushQuery.equalTo("username",username);

                  //Send Push message
                  Parse.Push.send({
                                  where: pushQuery,
                                  data: {
                                  alert: "New Ticket Added",
                                  sound: "default"
                                  }
                                  },{
                                  success: function(){
                                  response.success('true');
                                  },
                                  error: function (error) {
                                  response.error(error);
                                  }
                 });




});
Sign up to request clarification or add additional context in comments.

Comments

0

You have to add a filter to the pushQuery for the user created the object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.