feature: add event listeners to get answers from Base.send method only when explicitly asked #47

Merged
laurynas-karvelis merged 3 commits from feature/prevent-event-listener-overflow into master 2018-12-24 12:00:50 +00:00
Showing only changes of commit 68eb5e5483 - Show all commits

View File

@ -28,7 +28,7 @@ export default class Base extends EventEmitter {
* @param {boolean} expectAnswer whether a sent message expects an answer from a contact(s) * @param {boolean} expectAnswer whether a sent message expects an answer from a contact(s)
* @return {Promise} returns a promise, resolved with message:answer * @return {Promise} returns a promise, resolved with message:answer
*/ */
send(bot, expectAnswer = false) { send(bot, expectAnswer = true) {
if (this._keyboard) { if (this._keyboard) {
const replyMarkup = JSON.stringify(this._keyboard.getProperties()); const replyMarkup = JSON.stringify(this._keyboard.getProperties());
this.properties.reply_markup = replyMarkup; this.properties.reply_markup = replyMarkup;
@ -43,7 +43,8 @@ export default class Base extends EventEmitter {
.then(messageId => { .then(messageId => {
if (!expectAnswer) { if (!expectAnswer) {
// no need to add more event callbacks for the messages that don't need expect an answer // no need to add more event callbacks for the messages that don't need expect an answer
return resolve(); resolve();
return;
} }
const chat = this.properties.chat_id; const chat = this.properties.chat_id;
@ -73,8 +74,6 @@ export default class Base extends EventEmitter {
bot.removeListener('update', listener); bot.removeListener('update', listener);
} }
}); });
return void 0;
}) })
.catch(reject) .catch(reject)
.finally(() => { .finally(() => {