ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 206 forks source link

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

Open davidvavra opened 8 years ago

davidvavra commented 8 years ago

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 commented 8 years ago

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

Check out this great example by @hypesystem.

davidvavra commented 8 years ago

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 commented 8 years ago

Definitely not something we considered before, but interesting nonetheless.

@hypesystem what do you think about this?

scriby commented 8 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Here's a PR for a change of documentation: https://github.com/ToothlessGear/node-gcm/pull/323

johanforssell commented 6 years ago

323 is merged, this issue can be closed

davidvavra commented 6 years ago

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.

hypesystem commented 6 years ago

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