RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
39.82k stars 10.24k forks source link

How to remove orphan push tokens? #6776

Open rasos opened 7 years ago

rasos commented 7 years ago

We see many push tokens in the log as a queue, which could not be delivered and then hold back new push notifications. This is happening e.g. to users, who do not have an Android phone with Google services enabled, and then switch to another device with Google service enabled. They never get a push notifications, even after weeks.

[34mI20170424-16:09:06.164(2) Push: Could not send notification id: "MRQxxxxxxDyoe9PK", Error: Push.send got a faulty query
[34mI20170424-16:09:06.168(2) Push: Send message "user.test" via query { userId: 'fjCWxDLkbf8K95thD' }

As soon as we remove the tokens from "_raix_push_app_tokens" in the Mongo DB, the push notifications are successfully delivered.

We thought about removing all tokens in a cron job each night, but maybe there is a smarter solution? Or give the tokens a TTL.

Rocket.Chat Version: 0.52

laggedHero commented 7 years ago

On the Android side, we may be able to try to unregister when the user logs out of the server.

There's no hook on uninstall in order to make it happen. GCM/FCM will notify of an invalid token when trying to send a push and then we must remove it from the database (I think we already do it).

@rodrigok @sampaiodiego Maybe you guys known better about the server-side code.

TheReal1604 commented 7 years ago

@laggedHero duplicate. https://github.com/RocketChat/Rocket.Chat/issues/4574

mrsimpson commented 7 years ago

👍 A chat without push notifications is quite useless.

It looks like the removing of obsolete tokens was already implemented: /server/lib/cordova.js

return HTTP.post(`${ RocketChat.settings.get('Push_gateway') }/push/${ service }/send`, data, function(error, response) {
        if (response && response.statusCode === 406) {
            console.log('removing push token', token);
            Push.appCollection.remove({
                $or: [{
                    'token.apn': token
                }, {
                    'token.gcm': token
                }]
            });
            return;
        }

Still I experience the issue that after some installations and re-installations, I don't receive push notifications via the rocket chat gateway anymore:

settings_push

Any advice?

rasos commented 7 years ago

Any news on this issue? We have several users with orphan iOS tokens who do not get push notifications, unless we delete "_raix_push_app_tokens" in the Mongo DB. We could not observe a "removing push token" in the log file, so just wondering if the query "response.statusCode === 406" is applicable in the code snippet above.