Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy way to know which registrationTokens to replace/remove in your database #226

Open
davidvavra opened this issue Apr 15, 2016 · 10 comments

Comments

@davidvavra
Copy link

davidvavra commented Apr 15, 2016

According to GCM documentation, implementations of GCM server should replace or remove some registrationTokens from database in some cases like when the app was uninstalled from user's phone. I looked in the code and the information is hidden in the response object. It would be great if the developer can get a simple callback "replace these regTokens with these" and "remove these regTokens"

@eladnava
Copy link
Collaborator

Hi @davidvavra,
This is definitely made possible by node-gcm.

Check out this great example by @hypesystem.

@davidvavra
Copy link
Author

Yes I know it's possible. But it's not easy - developer needs to understand the concepts from the official documentation and write some non-trivial logic to detect which registrationIds to replace and which to remove. The library could make developer's life easier and provide two clear callbacks.

@eladnava
Copy link
Collaborator

eladnava commented Apr 17, 2016

Definitely not something we considered before, but interesting nonetheless.

@hypesystem what do you think about this?

@eladnava eladnava reopened this Apr 17, 2016
@scriby
Copy link

scriby commented Apr 28, 2016

I am implementing GCM now and this is something I was looking for in the documentation (similar to https://github.com/argon/node-apn).

@johanforssell
Copy link
Contributor

A simple example on how you could collect the "bad tokens"

const userTokens = [ /* we're sending to these tokens */ ];
const results = response.results; // callback from .send()

const collectBadTokens = (userTokens, results) => 
    results.filter(({ error }) => !!error)
    .map((_, i) => userTokens[i]);

This issue needs to be documented, it's kind of silly that you have to dig through the issues to find it.

@eladnava
Copy link
Collaborator

Thanks @johanforssell for the example code. I think you're right, we can easily add this to the main README. What do you think @hypesystem?

@johanforssell
Copy link
Contributor

johanforssell commented May 26, 2018

Here's a PR for a change of documentation: #323

@johanforssell
Copy link
Contributor

#323 is merged, this issue can be closed

@davidvavra
Copy link
Author

Well my intention was that "get bad tokens" would be part of the library API and people won't have to implement it, since everybody who uses the library has to do it. But a documented way is definitely an improvement.

@eladnava eladnava closed this as completed Oct 3, 2018
@hypesystem
Copy link
Collaborator

To be honest, a built-in way would be great 😄 if you feel like doing a PR on it, @davidvavra, we would definitely merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants