Parse Sends push notifications to a specific user from the cloud

I want to send a push notification from a cloud parsing code for a specific user. Therefore, I created a user section in the setup class of my parsing table, and I save the identifier of the user object there, so I can target the user by id and send push from the 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 the condition https://www.dropbox.com/s/1mb3pb2izb0jlj9/pushs.PNG?dl=0

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

This class has ACL enabled. What I want to do is very simple to send push to the user who created the object via 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

+5
source share
2 answers

This could 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); } }); }); 
+10
source

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

0
source

Source: https://habr.com/ru/post/1206515/


All Articles