X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fnotifier.ts;h=740c274d72116cd1b4edf0c310bffffbb03c8be6;hb=53c06121a45a2ec943002833a0152bbfd4856ee4;hp=5c50fcf01b355891c579f46cab29bb5b57209cd4;hpb=594d3e48d8a887bbf48ce4cc594c1c36c9640fb1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts index 5c50fcf01..740c274d7 100644 --- a/server/lib/notifier.ts +++ b/server/lib/notifier.ts @@ -1,4 +1,4 @@ -import { AbuseMessageModel } from '@server/models/abuse/abuse-message' +import { AccountModel } from '@server/models/account/account' import { getServerActor } from '@server/models/application/application' import { ServerBlocklistModel } from '@server/models/server/server-blocklist' import { @@ -137,7 +137,7 @@ class Notifier { }) } - notifyOnAbuseMessage (abuse: MAbuseFull, message: AbuseMessageModel): void { + notifyOnAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage): void { this.notifyOfNewAbuseMessage(abuse, message) .catch(err => { logger.error('Cannot notify on new abuse %d message.', abuse.id, { err }) @@ -436,6 +436,8 @@ class Notifier { const url = this.getAbuseUrl(abuse) logger.info('Notifying reporter and moderators of new abuse message on %s.', url) + const accountMessage = await AccountModel.load(message.accountId) + function settingGetter (user: MUserWithNotificationSetting) { return user.NotificationSetting.abuseNewMessage } @@ -452,20 +454,20 @@ class Notifier { } function emailSenderReporter (emails: string[]) { - return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message }) + return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message, accountMessage }) } function emailSenderModerators (emails: string[]) { - return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message }) + return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message, accountMessage }) } async function buildReporterOptions () { // Only notify our users - if (abuse.ReporterAccount.isOwned() !== true) return + if (abuse.ReporterAccount.isOwned() !== true) return undefined const reporter = await UserModel.loadByAccountActorId(abuse.ReporterAccount.actorId) // Don't notify my own message - if (reporter.Account.id === message.accountId) return + if (reporter.Account.id === message.accountId) return undefined return { users: [ reporter ], settingGetter, notificationCreator, emailSender: emailSenderReporter } } @@ -475,20 +477,21 @@ class Notifier { // Don't notify my own message moderators = moderators.filter(m => m.Account.id !== message.accountId) - if (moderators.length === 0) return + if (moderators.length === 0) return undefined return { users: moderators, settingGetter, notificationCreator, emailSender: emailSenderModerators } } - const [ reporterOptions, moderatorsOptions ] = await Promise.all([ + const options = await Promise.all([ buildReporterOptions(), buildModeratorsOptions() ]) - return Promise.all([ - this.notify(reporterOptions), - this.notify(moderatorsOptions) - ]) + return Promise.all( + options + .filter(opt => !!opt) + .map(opt => this.notify(opt)) + ) } private async notifyModeratorsOfVideoAutoBlacklist (videoBlacklist: MVideoBlacklistLightVideo) {