From 6d1c9700b15f9979df09cc8b3e41720c383431ce Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 3 Sep 2019 23:04:44 -0700 Subject: [PATCH] this.stop guard on channelAPI --- js/modules/loki_public_chat_api.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index deafffe87..9706bc78a 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -212,6 +212,7 @@ class LokiPublicChannelAPI { this.modStatus = false; this.deleteLastId = 1; this.timers = {}; + this.stop = false; // end properties log.info(`registered LokiPublicChannel ${channelId}`); @@ -223,6 +224,7 @@ class LokiPublicChannelAPI { } stop() { + this.stop = true; if (this.timers.channel) { clearTimeout(this.timers.channel); } @@ -387,9 +389,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat deletions: ${e}`); } - this.timers.channel = setTimeout(() => { - this.pollForChannelOnce(); - }, PUBLICCHAT_CHAN_POLL_EVERY); + if (!this.stop) { + this.timers.channel = setTimeout(() => { + this.pollForChannelOnce(); + }, PUBLICCHAT_CHAN_POLL_EVERY); + } } // update room details @@ -429,9 +433,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat deletions: ${e}`); } - this.timers.delete = setTimeout(() => { - this.pollForDeletions(); - }, PUBLICCHAT_DELETION_POLL_EVERY); + if (!this.stop) { + this.timers.delete = setTimeout(() => { + this.pollForDeletions(); + }, PUBLICCHAT_DELETION_POLL_EVERY); + } } async pollOnceForDeletions() { @@ -481,9 +487,11 @@ class LokiPublicChannelAPI { } catch (e) { log.warn(`Error while polling for public chat messages: ${e}`); } - setTimeout(() => { - this.timers.message = this.pollForMessages(); - }, PUBLICCHAT_MSG_POLL_EVERY); + if (!this.stop) { + setTimeout(() => { + this.timers.message = this.pollForMessages(); + }, PUBLICCHAT_MSG_POLL_EVERY); + } } async pollOnceForMessages() {