From 4cf58bd9f569bb46281817b370d0bbe517ce8b1b Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Fri, 12 Jul 2019 14:21:25 +0300 Subject: [PATCH] Reminders: fix double/triple/etc. posting after reload --- src/plugins/Reminders.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/Reminders.ts b/src/plugins/Reminders.ts index e4f40d67..4449144f 100644 --- a/src/plugins/Reminders.ts +++ b/src/plugins/Reminders.ts @@ -27,6 +27,7 @@ export class RemindersPlugin extends ZeppelinPlugin { protected tries: Map; private postRemindersTimeout; + private unloaded = false; getDefaultOptions(): IPluginOptions { return { @@ -51,6 +52,11 @@ export class RemindersPlugin extends ZeppelinPlugin { this.postDueRemindersLoop(); } + onUnload() { + clearTimeout(this.postRemindersTimeout); + this.unloaded = true; + } + async postDueRemindersLoop() { const pendingReminders = await this.reminders.getDueReminders(); for (const reminder of pendingReminders) { @@ -74,7 +80,9 @@ export class RemindersPlugin extends ZeppelinPlugin { await this.reminders.delete(reminder.id); } - this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME); + if (!this.unloaded) { + this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME); + } } @d.command("remind", " [reminder:string$]", {