From d3a25b935aae35dd97ef0f168ac7e2898126a9a5 Mon Sep 17 00:00:00 2001 From: sct Date: Tue, 30 Mar 2021 21:02:33 +0900 Subject: [PATCH] fix(notifications): correctly send notifications for users that do not have any user settings yet fixes #1324 --- server/lib/notifications/agents/discord.ts | 2 +- server/lib/notifications/agents/email.ts | 18 +++++++++--------- server/lib/notifications/agents/telegram.ts | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/server/lib/notifications/agents/discord.ts b/server/lib/notifications/agents/discord.ts index fa4d7d91d..cefde1861 100644 --- a/server/lib/notifications/agents/discord.ts +++ b/server/lib/notifications/agents/discord.ts @@ -218,7 +218,7 @@ class DiscordAgent if ( payload.notifyUser && - payload.notifyUser.settings?.enableNotifications && + (payload.notifyUser.settings?.enableNotifications ?? true) && payload.notifyUser.settings?.discordId ) { mentionedUsers.push(payload.notifyUser.settings.discordId); diff --git a/server/lib/notifications/agents/email.ts b/server/lib/notifications/agents/email.ts index 8fbb803af..ea6b02ef5 100644 --- a/server/lib/notifications/agents/email.ts +++ b/server/lib/notifications/agents/email.ts @@ -1,13 +1,13 @@ -import { BaseAgent, NotificationAgent, NotificationPayload } from './agent'; -import { hasNotificationType, Notification } from '..'; import path from 'path'; -import { getSettings, NotificationAgentEmail } from '../../settings'; -import logger from '../../../logger'; import { getRepository } from 'typeorm'; +import { hasNotificationType, Notification } from '..'; +import { MediaType } from '../../../constants/media'; import { User } from '../../../entity/User'; -import { Permission } from '../../permissions'; +import logger from '../../../logger'; import PreparedEmail from '../../email'; -import { MediaType } from '../../../constants/media'; +import { Permission } from '../../permissions'; +import { getSettings, NotificationAgentEmail } from '../../settings'; +import { BaseAgent, NotificationAgent, NotificationPayload } from './agent'; class EmailAgent extends BaseAgent @@ -154,7 +154,7 @@ class EmailAgent try { if ( payload.notifyUser && - payload.notifyUser.settings?.enableNotifications + (payload.notifyUser.settings?.enableNotifications ?? true) ) { const email = new PreparedEmail(payload.notifyUser.settings?.pgpKey); @@ -258,7 +258,7 @@ class EmailAgent try { if ( payload.notifyUser && - payload.notifyUser.settings?.enableNotifications + (payload.notifyUser.settings?.enableNotifications ?? true) ) { const email = new PreparedEmail(payload.notifyUser.settings?.pgpKey); @@ -307,7 +307,7 @@ class EmailAgent try { if ( payload.notifyUser && - payload.notifyUser.settings?.enableNotifications + (payload.notifyUser.settings?.enableNotifications ?? true) ) { const email = new PreparedEmail(payload.notifyUser.settings?.pgpKey); diff --git a/server/lib/notifications/agents/telegram.ts b/server/lib/notifications/agents/telegram.ts index 2445c7fdb..5fa4c5189 100644 --- a/server/lib/notifications/agents/telegram.ts +++ b/server/lib/notifications/agents/telegram.ts @@ -1,8 +1,8 @@ import axios from 'axios'; import { hasNotificationType, Notification } from '..'; +import { MediaType } from '../../../constants/media'; import logger from '../../../logger'; import { getSettings, NotificationAgentTelegram } from '../../settings'; -import { MediaType } from '../../../constants/media'; import { BaseAgent, NotificationAgent, NotificationPayload } from './agent'; interface TelegramMessagePayload { @@ -180,7 +180,7 @@ class TelegramAgent // Send user notification if ( payload.notifyUser && - payload.notifyUser.settings?.enableNotifications && + (payload.notifyUser.settings?.enableNotifications ?? true) && payload.notifyUser.settings?.telegramChatId && payload.notifyUser.settings?.telegramChatId !== this.getSettings().options.chatId