So my biggest problem is that I never wrote a single line of javascript before but as I developing my application it has become more and more clear I have to use it in Cloud Code.
I have a parse class named Groups, in this I store groups with the following data:
Name, Description, Users, Requests.
If a user creates a group from their device it will be here with the given name, description and the user pointer in it, and I'm using the new objectId with a + "C" char (sometimes objectId starts with a number but its not valid for a channal) to subscripte that user ( installation ) to a channel, so if I query the groups, I get the objectId and I can send every member of the group a push notification.
My first problem is here, that if i store the channel to a installation object in parse with the following code:
groups = new Groups();
groups.setName(groupName.getText().toString());
groups.put("members", ParseUser.getCurrentUser());
groups.setDesc(description.getText().toString());
groups.saveEventually(new SaveCallback() {
@Override
public void done(ParseException e) {
//Subscribe to push
ParsePush.subscribeInBackground("C" + groups.getObjectId(), new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push",
"successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
If the user has multiple devices then he wont get the push notifications on every device just on that where he created the group. I searched for it and I am sure I have to use a Parse Cloud function for the subscribing process and with it all the Installations of a specific user will subscribe to the same channels.
Here is my first problem. Can anyone help with it or just give me some reference to solve this (I read all the Cloud Documentation)
Notice: After the registration I add the user pointer to the Installation like this:
ParseInstallation.getCurrentInstallation().put("user", ParseUser.getCurrentUser());
My second problem:
As I find others have problem with it too and there was some solutions but my problem is a bit more complex. So as I noticed, if I send a client side notification from a device, it will be delivered to the selected channels, it working fine, but if I delete the application then reinstall it, and I'm sending client side notification, it wont delete the multiple installation objects for the device and I will get the notification twice
(I know that if I send notification from parse dashboard it is doing the delete job).
So I need a cloud function that is checking that if there is an other installation with the same user and androidId ( added at install, get it from Android Security ) , if there, then delete it, check if there is an other installation with the same user but not with the same andoidId, copy that installation's channels to my new one and then save the new installation.
Same as above, reference, example code, anything.
I think it will be usefull for others too and hope that someone can help me.
(P.S.: If you need more information please comment, I will always answer in 24 hours)