Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

How to remove orphan push tokens?

Open rasos opened this issue 9 years ago • 4 comments

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

rasos avatar Apr 24 '17 14:04 rasos

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.

laggedHero avatar Apr 25 '17 12:04 laggedHero

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

TheReal1604 avatar Apr 25 '17 13:04 TheReal1604

👍 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?

mrsimpson avatar Apr 28 '17 08:04 mrsimpson

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.

rasos avatar Aug 21 '17 06:08 rasos