Andrew
Andrew

Reputation: 3989

Unable to set Parse installation to two channels for push notification

I'm trying to have a part of my Parse cloud code set the installation channel for push notification purposes. I want it to set the installation to two channels like so:

var installationQuery = new Parse.Query(Parse.Installation);
installationQuery.equalTo('userId', user);

installationQuery.first().then(function(result) {
   result.set('channels', [user, "highPush"]);
   result.save();
});

What I'm doing here is finding the installation associated with a particular userId, then setting that installation object's 'channels' property to both the username ( the user variable) string, and the string "highPush".

The problem is that running this code only seems to set it to "highPush", not both. When I try using an explicit user string like below, it successfully sets it to both, but not when I use the user variable which contains that same userId string. What could be causing this?

result.set('channels', ["EG7Mf6mDkT", "highPush"]);

Logging the user variable like below succesfully prints, so I know it exists.

console.log('set it to high push, and the userId is' + user);

Upvotes: 0

Views: 163

Answers (1)

Fosco
Fosco

Reputation: 38526

I'm skeptical that user is really a string here. Are you sure that user isn't a Parse.User?

If it is indeed a Parse.User object, get at the objectId with:

result.set('channels', [user.id, "highPush"]);

Upvotes: 1

Related Questions