Meteor-Community-Packages / raix-push

DEPRECATED: Push notifications for cordova (ios, android) browser (Chrome, Safari, Firefox)
https://atmospherejs.com/raix/push
MIT License
515 stars 197 forks source link

Push.setMetadata working? #171

Open farconada opened 8 years ago

farconada commented 8 years ago

Hi I'm trying to attach some metadata to my tokens but not sure if it's my fault or a bug I want to filter messages by channels and channels could be changed by the app user In my code

Meteor.startup(function () {
    Push.addListener('message', function(notification) {
        // Called on every message
        console.log(JSON.stringify(notification));
    });
    Push.setMetadata({channels: ['all', 'news', 'events', 'alerts', 'advises']});
});

log

20151219-23:04:22.930(1)? Push: Got push token from app: { id: 'xRb8wSmbbfRmtChCT',
I20151219-23:04:22.931(1)?   token: { gcm: 'xxx' },
I20151219-23:04:22.931(1)?   appName: 'main',
I20151219-23:04:22.931(1)?   userId: null,
I20151219-23:04:22.931(1)?   metadata: { channels: [ 'all', 'news', 'events', 'alerts', 'advises' ] } }
I20151219-23:04:22.936(1)? Push: updated { _id: 'xRb8wSmbbfRmtChCT',
I20151219-23:04:22.936(1)?   token: { gcm: 'xxx },
I20151219-23:04:22.936(1)?   appName: 'main',
I20151219-23:04:22.936(1)?   userId: null,
I20151219-23:04:22.936(1)?   enabled: true,
I20151219-23:04:22.936(1)?   createdAt: Sat Dec 19 2015 22:38:26 GMT+0100 (CET),
I20151219-23:04:22.937(1)?   updatedAt: Sat Dec 19 2015 22:58:50 GMT+0100 (CET) }

In mongo

{
    "_id" : "sRb8wSmbafRmtChCT",
    "token" : {
        "gcm" : "xxx"
    },
    "appName" : "main",
    "userId" : null,
    "enabled" : true,
    "createdAt" : ISODate("2015-12-19T21:38:26.423Z"),
    "updatedAt" : ISODate("2015-12-19T22:04:22.932Z")
}
LarsBuur commented 7 years ago

I was struggling with this one as well. For future readers and maybe @farconada the problem is that client/client.js where setMetaData is defined requires that the token is set before you call Push.setMetaData. Otherwise the metaData is only kept in localstorage.

The obvious chose for me was to just add my setMetaData code into the

Push.addListener('token', function(token) {
    console.log('########### Hello from token listener:' + JSON.stringify(token));

Push.setMetaData({tada:'todo'});

});
jf-patenaude commented 6 years ago

Thank you for this piece of code. As simple as it can look, it helped me a lot!