From c41f7a09787374ec193a5fb24f0ca84d9066accf Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Tue, 18 Feb 2020 01:22:00 +0100 Subject: [PATCH] Change to comma separated list --- src/data/Thread.js | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/data/Thread.js b/src/data/Thread.js index fad9c36..6858d5c 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -169,8 +169,15 @@ class Thread { } if (this.alert_id) { + const ids = this.alert_id.split(","); + let mentions = ""; + + ids.forEach(id => { + mentions += `<@!${id}> `; + }); + await this.deleteAlerts(); - await this.postSystemMessage(`${this.alert_id} New message from ${this.user_name}`); + await this.postSystemMessage(`${mentions}New message from ${this.user_name}`); } } @@ -457,13 +464,15 @@ class Thread { alerts = alerts.alert_id; if (alerts == null) { - alerts = `<@!${userId}>`; + alerts = [userId] } else { - if (! alerts.includes(`<@!${userId}>`)) { - alerts += ` <@!${userId}>`; + alerts = alerts.split(","); + if (!alerts.includes(userId)) { + alerts.push(userId); } } + alerts = alerts.join(","); await knex('threads') .where('id', this.id) .update({ @@ -482,12 +491,20 @@ class Thread { .first(); alerts = alerts.alert_id; - if (! (alerts == null)) { - if (alerts.startsWith(`<@!${userId}>`)) { // we do this to properly handle the spacing between @s - alerts = alerts.replace(`<@!${userId}> `, ""); - } else { - alerts = alerts.replace(` <@!${userId}>`, ""); + if (alerts != null) { + alerts = alerts.split(","); + + for (let i = 0; i < alerts.length; i++) { + if (alerts[i] == userId) { + alerts.splice(i, 1); + } } + } else return; + + if (alerts.length == 0) { + alerts = null; + } else { + alerts = alerts.join(","); } await knex('threads')