Change to comma separated list

cshd
Dark 2020-02-18 01:22:00 +01:00
parent 949a5efdb2
commit c41f7a0978
1 changed files with 26 additions and 9 deletions

View File

@ -169,8 +169,15 @@ class Thread {
} }
if (this.alert_id) { if (this.alert_id) {
const ids = this.alert_id.split(",");
let mentions = "";
ids.forEach(id => {
mentions += `<@!${id}> `;
});
await this.deleteAlerts(); 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; alerts = alerts.alert_id;
if (alerts == null) { if (alerts == null) {
alerts = `<@!${userId}>`; alerts = [userId]
} else { } else {
if (! alerts.includes(`<@!${userId}>`)) { alerts = alerts.split(",");
alerts += ` <@!${userId}>`; if (!alerts.includes(userId)) {
alerts.push(userId);
} }
} }
alerts = alerts.join(",");
await knex('threads') await knex('threads')
.where('id', this.id) .where('id', this.id)
.update({ .update({
@ -482,13 +491,21 @@ class Thread {
.first(); .first();
alerts = alerts.alert_id; alerts = alerts.alert_id;
if (! (alerts == null)) { if (alerts != null) {
if (alerts.startsWith(`<@!${userId}>`)) { // we do this to properly handle the spacing between @s alerts = alerts.split(",");
alerts = alerts.replace(`<@!${userId}> `, "");
} else { for (let i = 0; i < alerts.length; i++) {
alerts = alerts.replace(` <@!${userId}>`, ""); if (alerts[i] == userId) {
alerts.splice(i, 1);
} }
} }
} else return;
if (alerts.length == 0) {
alerts = null;
} else {
alerts = alerts.join(",");
}
await knex('threads') await knex('threads')
.where('id', this.id) .where('id', this.id)