diff --git a/lib/telegram.link.js b/lib/telegram.link.js index fb71138..4fa4a35 100644 --- a/lib/telegram.link.js +++ b/lib/telegram.link.js @@ -316,13 +316,7 @@ Client.prototype.stopHttpPollLoop = function () { // The code: Client.prototype.registerOnUpdates = function (callback) { - var emitter = this._channel.getParser(); - emitter.on('api.type.UpdatesTooLong', callback); - emitter.on('api.type.UpdateShortMessage', callback); - emitter.on('api.type.UpdateShortChatMessage', callback); - emitter.on('api.type.UpdateShort', callback); - emitter.on('api.type.UpdatesCombined', callback); - emitter.on('api.type.Updates', callback); + manageUpdatesListener.call(this, 'on', callback); }; // *** @@ -332,15 +326,19 @@ Client.prototype.registerOnUpdates = function (callback) { // The code: Client.prototype.unregisterOnUpdates = function (callback) { - var emitter = this._channel.getParser(); - emitter.removeListener('api.type.UpdatesTooLong', callback); - emitter.removeListener('api.type.UpdateShortMessage', callback); - emitter.removeListener('api.type.UpdateShortChatMessage', callback); - emitter.removeListener('api.type.UpdateShort', callback); - emitter.removeListener('api.type.UpdatesCombined', callback); - emitter.removeListener('api.type.Updates', callback); + manageUpdatesListener.call(this, 'removeListener', callback); }; +function manageUpdatesListener (func, callback) { + var emitter = this._channel.getParser(); + emitter[func]('api.type.UpdatesTooLong', callback); + emitter[func]('api.type.UpdateShortMessage', callback); + emitter[func]('api.type.UpdateShortChatMessage', callback); + emitter[func]('api.type.UpdateShort', callback); + emitter[func]('api.type.UpdatesCombined', callback); + emitter[func]('api.type.Updates', callback); +} + // *** // client.**isReady()**