gonzaloaune / GCMPushPlugin

Push notifications for Cordova (GCM & Native support)
MIT License
37 stars 20 forks source link

added support for subscribe to topic , un-subscribe to topic #8

Open scripterkaran opened 9 years ago

scripterkaran commented 9 years ago

This provides added support to subscribe to GCM topics.

PS: Please create a development branch so we contributors can contribute without messing the master repo.

akreienbring commented 9 years ago

@promactkaran Please have a look at my fork https://github.com/akreienbring/GCMPushPlugin

I also added Topic support (for Android). Would you mind using the same interface to make it easier to merge both?

/**
 * Subscribe to a topic
 * @param registrationId, The registration id that was optained during registration
 * @param topics, an array of topics that may not be empty
 * @throws an error if not all parameters are provided or the plugin fails during the subscription
 */
GcmPushPlugin.prototype.subscribeTopics = function (registrationId, topics) {
    if(!registrationId || !topics || topics[0] == null){
        throw new Error("GcmPushPluginError", "Please provide the registrationId and at least one topic.")
    }else{
        exec(this.successCB, this.errorCB, "GCMPushPlugin", "subscribeTopics", [{registrationId: registrationId, topics: topics}]);
    };
};

/**
 * Unsubscribe from a topic
 * @param registrationId, The registration id that was optained during registration
 * @param topics, an array of topics that may not be empty
 * @throws an error if not all parameters are provided or the plugin fails during the unsubscription
 */
GcmPushPlugin.prototype.unsubscribeTopics = function (registrationId, topics) {
    if(!registrationId || !topics || topics[0] == null){
        throw new Error("GcmPushPluginError", "Please provide the registrationId and at least one topic.")
    }else{
        exec(this.successCB, this.errorCB, "GCMPushPlugin", "unsubscribeTopics", [{registrationId: registrationId, topics: topics}]);
    };
};
scripterkaran commented 9 years ago

The thing is, I am not sending registration Id in my topic subscription. The registration Id is stored in a dictionary by OS itself.

When I register to topic, it automatically takes the device registration ID and registers the device to specific topic. I wouldn't have to deal with storing the ID , in javascript Side.

What do you suggest ?

akreienbring commented 9 years ago

Ok... maybe it makes sense to have the same behaviour on Android. I could store the token in the Plugin once the registration took place.

akreienbring commented 8 years ago

I just removed the need to pass the registrationId when subcribing / unsubscribing to topics.

The token is now hold in the plugin once you registered with gcm.

akreienbring commented 8 years ago

@scripterkaran It seems that Gonzalo has no interest in merging our improvements :-( What do you think of merging yours and mine? If you offer me a pull request I would be glad to accept it. But I would prefer the event based approach I introduced to the plugin. What do you think?

gonzaloaune commented 8 years ago

I'll be reviewing everything today guys, I had some personal things to take care. Thanks for everything.

On Sunday, October 18, 2015, André Kreienbring notifications@github.com wrote:

@scripterkaran https://github.com/scripterkaran It seems that Gonzalo has no interest in merging our improvements :-( What do you think of yours and mine? If you offer me a pull request I would be glad to merge it. But I would prefer the event bases approach I introduced to the plugin. What do you think?

— Reply to this email directly or view it on GitHub https://github.com/gonzaloaune/GCMPushPlugin/pull/8#issuecomment-149000776 .

G.-